[lug] Q: retrieving script name from within script alternative

Chan Kar Heng karheng at softhome.net
Sat Jul 2 01:58:02 MDT 2005


hi there.

is there an alternative method for script name retrieval from within a 
script?

eg:
i've a script called a.sh.
from a.sh, i use $0 with basename to get the script name.
i can use cd `dirname $0` followed by DIR=`pwd` to retrieve directory of 
the script.
this doesn't work however, if i source the script like this:

. ./a.sh

$0 is assigned -, which means it's the login shell.

dug around over the net, but the answer seems elusive
(can't figure out any better keywords to search with).

any guru might have any ideas?

the script i have there is actually a script containing settings,
& i need it to initialize environment variables to the folder it is in, 
etc. sorta like saying JAVA_HOME=`dirname $0`...

btw, for people here who dual boot windoz & linux, try out colinux.
i've just tried it out & it seems pretty good so far.
allows linux to run from within windows, but in different way from 
machine virtualisation.


thanks & rgds,

kh




More information about the LUG mailing list