bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Modifying $0?


From: Paul Jarc
Subject: Re: Modifying $0?
Date: Thu, 08 Jul 2004 12:08:14 -0400
User-agent: Gnus/5.110003 (No Gnus v0.3) Emacs/21.3 (gnu/linux)

Davy Durham <pubaddr@davyandbeth.com> wrote:
> Paul Jarc wrote:
>> #!/bin/sh
>> if [ "$0" != what-you-want ]; then
>>   exec /bin/sh -c '. "$@"' what-you-want "$0" ${1+"$@"}
>> fi
>
> I'm not entirely sure how this is working.  I understand the "$@", but
> does the '-c .' have a special meaning in bash?

Say the script is /foo/bar, and it is invoked with the argument "arg".
Initially, $0 is /foo/bar and $1 is arg.  Since $0 is not
what-you-want, the script execs the sh command:
/bin/sh -c '. "$@"' what-you-want /foo/bar arg
So now, $0 is
what-you-want, $1 is /foo/bar, and $2 is arg, and this sh will run the
command '. "$@"', which expands to '. /foo/bar arg'.  It sources the
script, setting the positional parameters with $1=arg.  "." is just
the builtin "source" command.


paul




reply via email to

[Prev in Thread] Current Thread [Next in Thread]