Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!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.shell Subject: Re: Finding a script's location (was: Re: comp.unix.questions) Message-ID: <27620003@hp-lsd.COS.HP.COM> Date: 12 Sep 90 17:39:54 GMT References: <9009101705.AA29830@mindcrf.mindcraft.com> Organization: HP Logic Systems Division - ColoSpgs, CO Lines: 33 The following script seems to meet all your requirements: i.e. works when executable is: in an absolute path in a relative path in a path specified by the PATH avariable. #! /bin/ksh # This script displays the path name of the script itself # from the command argument $0 name=$0 bname=`basename $name` ipth=${name%$bname} if [ "$bname" = "$name" ] then # Script somewhere on the path fpth=`whence $name` pth=${fpth%/$bname} else cd $ipth pth=$PWD fi print "Path to $0 is $pth" Jim Rogers Hewlett Packard Company