current dir from .command scripts

Hex Star hexstar at gmail.com
Sat Aug 4 14:05:34 PDT 2007


On 8/4/07, Andy Lee <aglee at mac.com> wrote:
>
> $0, $1, $2 etc. is replaced by the shell with the nth argument to the
> current command.  The zeroth argument, $0, is the command name
> itself, which is bash when you enter commands in your Terminal window.
>
> If you do "echo $0" at the shell, you get "-bash".  (I don't know why
> it's that instead of "/bin/bash".)  So "dirname $0" expands to
> "dirname -bash".  Putting backticks around "dirname $0" causes
> "dirname -bash" to be evaluated by the shell.  The shell thinks you
> are trying to pass a -b option to dirname, which it doesn't support.
>
> If you were to include "echo `dirname $0`" in a *script*, it would
> succeed, because the "zeroth" argument to the script is the path to
> the script file.
>
> --Andy
>
>
Ah I see, thanks for clarifying this for me. :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /mailman/archive/macosx-talk/attachments/20070804/bcf0c6ac/attachment.html


More information about the MacOSX-talk mailing list