Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!chinacat!uudell!ninja!root From: root@ninja.dell.com (Randy Davis) Newsgroups: comp.unix.questions Subject: Re: comp.unix.questions Summary: How about this Message-ID: <9434@uudell.dell.com> Date: 7 Sep 90 19:06:09 GMT References: <1990Sep7.152354.9439@ecn.purdue.edu> Sender: news@uudell.dell.com Reply-To: rjd@ninja.dell.com Organization: Dell Computer Corporation, Austin, TX Lines: 17 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\"" 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@ninja.dell.com --