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 13:41:58 -0400
User-agent: Gnus/5.110003 (No Gnus v0.3) Emacs/21.3 (gnu/linux)

Davy Durham <pubaddr@davyandbeth.com> wrote:
> I'm going to try to work around it with a conditional shift, but if
> you know why this is happening please let me know.

Ah: "." sets the positional parameters if any are given, or leaves
them unchanged otherwise.  So we can ensure that we specify at least
one, and then get rid of it later:

#!/bin/bash
if [ "$0" != what-you-want ]; then
  exec bash -c '. "$1" "$@"' what-you-want "$0" ${1+"$@"}
fi
shift
...

So now the "." command is '. /path/to/script /path/to/script args...'.
Even if there are no args, there is at least one extra argument for
".", so it will always set the positional parameters.  Then we shift
off the duplicate /path/to/script.


paul




reply via email to

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