Bash example
Nils Kassube
kassube at gmx.net
Fri Aug 21 11:38:30 UTC 2009
Florent Charton wrote:
> A solution among others :
> rmdir_if_exists() {
> [ $# -eq 1 ] || (echo "Need the directory name" >&2 ; exit 1)
> [ -d "$0" ] && rm -Rfv "$0"
> }
Kids, don't try this at home!
$0 is the binary of the shell which you definitely DON'T want to remove.
Or if you put this in a script it is the script itself. Yes, I know
there is a test for a directory before the rm command but someone who
tries to make this work might get rid of the test.
Florent, please TEST dangerous commands like the above on your own
machine before you post it on a list where there are newbies who might
render their system unusable.
Nils
More information about the ubuntu-users
mailing list