[comp.unix.shell] tail of a path

fitz@mml0.meche.rpi.edu (Brian Fitzgerald) (05/14/91)

afsipmh@cidsv01.cid.aes.doe.CA writes:
>Basically I want to be able to get the name of a script out
>of $0 without the path.

Use basename if it's available on your machine.  It's not a shell
builtin, though.  Use backquotes if you want to use the result in your
script.

prog=`basename $0`

Brian

weimer@garden.ssd.kodak.com (Gary Weimer (253-7796)) (05/15/91)

In article <=+_hsq.@rpi.edu>, fitz@mml0.meche.rpi.edu (Brian Fitzgerald)
writes:
|> afsipmh@cidsv01.cid.aes.doe.CA writes:
|> >Basically I want to be able to get the name of a script out
|> >of $0 without the path.
|> 
|> Use basename if it's available on your machine.  It's not a shell
|> builtin, though.  Use backquotes if you want to use the result in your
|> script.
|> 
|> prog=`basename $0`

or if you don't have basename (or don't want to worry about it):

prog=`echo $0|awk -f/ '{print $NF}'`

weimer@ssd.kodak.com ( Gary Weimer )