basename(1) (Was Re:argv[0] in shellscript?)

Matthew Squires squires at eecs.nwu.edu
Tue Jun 7 10:55:21 AEST 1988


/ eecs.nwu.edu:comp.unix.questions /
 davidsen at steinmetz.ge.com (William E. Davidsen Jr) 
/  1:15 pm  Jun  6, 1988 /

> In article <1813 at stpstn.UUCP> aad at stpstn.UUCP (Anthony A. Datri) writes:
> | 
> | I want to write a script that will have multiple links to it, and be
> | able to tell what name it was invoked with.  Ideas?
> 
>   How about $0? That's the name of the called program.  Watch out if you
> have a full pathname (ie.  $0 = foo/something). ...

Then perhaps you could use basename(1)...

BASENAME(1)         UNIX Programmer's Manual          BASENAME(1)

NAME
     basename - strip filename affixes

SYNOPSIS
     basename string [ suffix ]

DESCRIPTION
     Basename deletes any prefix ending in `/' and the suffix, if
     present in string, from string, and prints the result on the
     standard output. ...

% basename "foo"
foo
% basename "foo/something"
something
% 
Process shell finished


> 	bill davidsen		(wedu at ge-crd.arpa)
>   {uunet | philabs | seismo}!steinmetz!crdos1!davidsen
> "Stupidity, like virtue, is its own reward" -me

Matthew C. Squires, local GNUisance
squires at eecs.nwu.edu  OR  {ihnp4,oddjob,gargoyle,chinet}!nucsrl!squires



More information about the Comp.unix.questions mailing list