Bash example
Florent Charton
traydent at gmail.com
Fri Aug 21 12:19:39 UTC 2009
Le 21/08/2009 13:38, Nils Kassube a écrit :
> Florent Charton wrote:
>
>> A solution among others :
>> rmdir_if_exists() {
>> [ $# -eq 1 ] || (echo "Need the directory name" >&2 ; exit 1)
>> [ -d "$1" ] && rm -iRfv "$1"
>> }
>>
[Changed to no more quote erroneous script]
> 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.
>
Sorry for my mistake. And in addition, $0 refers to the first "word" of
the command, so it would be rmdir_if_exists, didn't it ?
> 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.
>
I'll remember this for the future.
> Nils
>
More information about the ubuntu-users
mailing list