Path: utzoo!attcan!uunet!aplcen!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!sdd.hp.com!hplabs!hpfcso!hpldola!hp-lsd!jimr From: jimr@hp-lsd.COS.HP.COM (Jim Rogers) Newsgroups: comp.unix.questions Subject: Re: Which script (was Re: comp.unix.questions) Message-ID: <7370013@hp-lsd.COS.HP.COM> Date: 12 Sep 90 17:03:30 GMT References: <563@DIALix.UUCP> Organization: HP Logic Systems Division - ColoSpgs, CO Lines: 45 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