comp.unix.questions

Randy Davis root at ninja.dell.com
Sat Sep 8 05:06:09 AEST 1990


In article <1990Sep7.152354.9439 at ecn.purdue.edu> patkar at helium.ecn.purdue.edu (The Silent Dodo) writes:
|I have a question about shell scripts.  How can a shell script
|(sh or csh) find out its own file name?  Actually, I need to
|know only the directory in which it resides.

   Hmmmmm..... Off the top of my head, how about this?:

COMMAND=`basename $0`
DIR=`type $COMMAND | sed -e 's:^.* /:/:' -e "s:/$COMMAND$::"`
echo "Parent directory of \"$COMMAND\" is \"$DIR\""

  It works under sh.  Although I am sure there is an "awk" script that might
do it in less lines, I bet this is possibly faster.

Randy Davis					UUCP: rjd at ninja.dell.com

-- 



More information about the Comp.unix.questions mailing list