|
Prev: Brand Watches Tissot Men's T-Race watch #T011.417.22.201.00 Discount, Swiss, Fake
Next: result of `which ./a.sh`
From: troyzeng on 24 Apr 2008 21:33 How to get the script name when sourcing it? ${0} returns '-bash'. Thanks a lot.
From: mop2 on 24 Apr 2008 21:46 $BASH_SOURCE troyzeng wrote: > How to get the script name when sourcing it? > ${0} returns '-bash'. > > Thanks a lot.
From: troyzeng on 24 Apr 2008 22:57 On 25 Apr, 11:46, mop2 <mop2bky4mz5tyjwa8ersp7hrg5u...(a)gmail.com> wrote: > $BASH_SOURCE > > troyzeng wrote: > > How to get the script name when sourcing it? > > ${0} returns '-bash'. > > > Thanks a lot. Thanks. That works for bash and sh. What about ksh? Thanks.
From: Stephane CHAZELAS on 25 Apr 2008 02:42
2008-04-24, 19:57(-07), troyzeng: > On 25 Apr, 11:46, mop2 <mop2bky4mz5tyjwa8ersp7hrg5u...(a)gmail.com> > wrote: >> $BASH_SOURCE >> >> troyzeng wrote: >> > How to get the script name when sourcing it? >> > ${0} returns '-bash'. >> >> > Thanks a lot. > > Thanks. That works for bash and sh. Only for sh where sh is implemented by bash, so only GNU systems. > What about ksh? Thanks. Depends on the implementation of ksh. In the zsh implementation, you'll find it in ${(%):-%N} (%N, in prompt expansion is expanded to the name of the currently sourced script (for PS2), (%) enables prompt expansion in parameter expansion ${:-default} is a special form of ${var:-default} which always expands to "default"). Portably, you could do: source() { sourced_script=$1 . "$1" } And use "source" instead of ".". And then use $sourced_script. -- St�phane |