msb65
April 26, 2010, 11:02am
1
Hi everyone,
Is there a slick way to determine the FULL name of a script that is running?
The variable
${0}
just gives the relative path name.
I guess I could just do the following:
FULL_SCRIPT_NAME=${PWD}${0}
Although that's pretty simple is there another way that I am missing?
Thanks a lot.
Mike
#!/bin/ksh
thisFile="$(whence ${0})"
msb65
April 26, 2010, 11:18am
3
Hi vgersh99,
I meant to specify that I am using the bash shell. A quick web search seems to indicate that whence is a ksh function, and whence ls does not work on my system. Am I correct about that? Any other suggestions?
If you're running bash, you may be on linux, and may thus have the general purpose command 'realpath'.
#!/bin/bash
#set -x
progpath=$(
progpath=$0
case $0 in
(*/*) ;; (*)
[ -e "$progpath" ] || progpath=$(command -v -- "$progpath") || exit
esac
cd -P -- "$(dirname -- "$progpath")" && pwd -P || exit
) || exit
progpath=$progpath/$(basename "$0")
echo "${progpath}"
comp.unix.shell