Re: Directory of currently executing script (ksh)

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.

[[ $0 = */* ]] || progdir=$PWD
. $progdir/common_code || exit 1

-- John Wiersba


Relevant Pages