Listing One: x() function for confirming wildcards x() { local ans echo “$@” | fmt echo -n “x: execute that command line? [yn](y) ” read ans case “$ans” in [yY]*|”") “$@” ;; *) echo “x: NOT executing: $*” | fmt ;; esac } |
$ x rm /a/b/0? rm /a/b/00 /a/b/01 /a/b/06 x: execute that command line? [yn](y) n x: NOT executing: rm /a/b/00 /a/b/01 /a/b/06
x() outputs the command line with long lines neatly wrapped by fmt, and then prompts (by not outputting a newline at the end) whether you want to execute the command or not. If you answer y or simply press RETURN, the command runs.
Would you like to comment?
Join Diigo for a free account, or sign in if you are already a member.