Which script (was Re: comp.unix.questions)
Jim Rogers
jimr at hp-lsd.COS.HP.COM
Thu Sep 13 03:03:30 AEST 1990
Following is a modest script in ksh to report the path of a script.
I suspect that this can be done much more elegantly. The beauty of this
script is that it works correctly.
#! /bin/ksh
# This script displays the path name of the script itself
# from the command argument $0
name=$0
# look for the path in the above directory
first=${name#..}
if [ "$first" != "$name" ]
then
cd ..
fpth=$PWD$first
else
# look for the path in the current directory
first=${name#.}
if [ "$first" != "$name" ]
then
fpth=$PWD$first
else
case $name in
# Absolute path specified
/*) fpath=$name; break;;
# relative path below current directory
*) fpath=$PWD/$name; break;;
esac
fi
fi
spath=`print $ppth | tr "/" " "`
for file in $spath
do
continue
done
pth=${fpath%/$file}
print "path to $name is $pth"
Jim Rogers
Hewlett Packard Company
More information about the Comp.unix.questions
mailing list