Bash example

Nils Kassube kassube at gmx.net
Fri Aug 21 12:40:18 UTC 2009


Florent Charton wrote:
> > $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 ?

It depends. If you use the command with an interactive shell (and not 
within a script), $0 refers to the binary of your shell, i.e. usually 
/bin/bash. If you change your function to only echo "$0" you can verify 
it. If you put your function in a script, $0 refers to that script.


Nils





More information about the ubuntu-users mailing list