|
From: | Davy Durham |
Subject: | Re: Modifying $0? |
Date: | Thu, 08 Jul 2004 12:52:03 -0400 |
User-agent: | Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040115 |
Paul Jarc wrote:
That's similar to what I ended up doing... Here's the final result frrom all your help: (I wanted it all as a single line as well)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.
#!/bin/bash[[ "$0" != what-i-want ]] && exec "$SHELL" -c 'source "$@"' what-i-want "$0" foo ${1+"$@"} || shift 1
...So, I put the extra parameter outside the -c '...' parameter which seems to work fine too. (Foresee any problems with that?)
Thanks yet again, Davy
[Prev in Thread] | Current Thread | [Next in Thread] |