Re: Directory of currently executing script (ksh)
- From: base60 <nobody@xxxxxxxxxxxxxx>
- Date: Sat, 06 May 2006 02:57:20 GMT
jrw32982@xxxxxxxxx wrote:
What's considered the best way to get the directory of the currently
executing script, in order to dot a script in the same directory? Is
there a better way than the code below?
What you have below is common.
An alternative is to use "man dirname"
I know of certain failure.
cases for this code (e.g. if the program was executed via a symbolic
link to the program, or if $0 doesn't accurately reflect the actual
program name). BTW, I don't want to depend on the caller's environment
being set up properly (e.g. FPATH). I want this to be reasonably
bulletproof and short, given the constraint that this code will be
duplicated in lots of places in order to include a common library.
progdir=${0%/*}
[[ $0 = */* ]] || progdir=$PWD
. $progdir/common_code || exit 1
Thanks!
-- John Wiersba
- References:
- Directory of currently executing script (ksh)
- From: jrw32982
- Directory of currently executing script (ksh)
- Prev by Date: Re: what does this test mean?
- Next by Date: Re: Directory of currently executing script (ksh)
- Previous by thread: Re: Directory of currently executing script (ksh)
- Next by thread: Re: Directory of currently executing script (ksh)
- Index(es):
Relevant Pages
|