Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!ibmps2!aix!nwosuck From: nwosuck@aix.aix.kingston.ibm.com (Kingsley Nwosu) Newsgroups: comp.unix.questions Subject: Re: comp.unix.questions Message-ID: <4043@aix.aix.kingston.ibm.com> Date: 11 Oct 90 16:38:03 GMT References: <1990Sep7.152354.9439@ecn.purdue.edu> <9434@uudell.dell.com> Organization: IBM Corporation, Kingston, NY Lines: 24 In article <9434@uudell.dell.com>, root@ninja.dell.com (Randy Davis) writes: > In article <1990Sep7.152354.9439@ecn.purdue.edu> patkar@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\"" > Why not do: echo "Directory name is `dirname $0`" in sh. Kingsley Nwosu ...uunet!ibmps2!aix!nwosuck IBM AIX Dev., Dept. 83HA/572, | Neighborhood Rd, Kingston, |"Advice to those about to get married: Don't!" NY 12401. |