argv[0] in shellscript?

William E. Davidsen Jr davidsen at steinmetz.ge.com
Tue Jun 7 04:15:56 AEST 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).  In that case use a case
to strip the leading name, like:

  case "$0" in
  foo | */foo)
    echo "Name is foo";;
  mumbl | */mumbl)
    echo "Name is mumbl";;
  *)
    echo "Name is wrong!";exit 1;;
  esac
-- 
	bill davidsen		(wedu at ge-crd.arpa)
  {uunet | philabs | seismo}!steinmetz!crdos1!davidsen
"Stupidity, like virtue, is its own reward" -me



More information about the Comp.unix.questions mailing list