Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!bloom-beacon!oberon!bbn!uwmcsd1!marque!uunet!mcvax!ukc!warwick!maujd From: maujd@warwick.UUCP (Geoff Rimmer) Newsgroups: comp.unix.questions Subject: csh :t modifier (Was Re: basename(1) (Was Re:argv[0] in shellscript?)) Message-ID: <709@ubu.warwick.UUCP> Date: 21 Jun 88 12:56:29 GMT References: <3680037@eecs.nwu.edu> <1813@stpstn.UUCP> Sender: news@warwick.UUCP Reply-To: maujd@warwick.UUCP (Geoff Rimmer) Organization: Computer Science, Warwick University, UK Lines: 58 In article <3680037@eecs.nwu.edu> squires@eecs.nwu.edu (Matthew Squires) writes: >> In article <1813@stpstn.UUCP> aad@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)... > > [ /usr/man/cat1/basename.1 deleted ] > I tend to use basename(1) in scripts mainly for printing a usage error message, e.g. ------------------------------------------------------------ #!/bin/csh -f if ($#argv != 0) then echo "Usage: `basename $0`" exit 1 endif cat /etc/passwd | sed "s/:[^:]*:[^:]*:[^:]*:/ /" | sed "s/[,:].*//" | sort ^^TAB^^ --------------------------------------------------------------------- (BTW, anyone got any improvements on this 'sed' line?) --------------------------------------------------------------------- What I want to know is, why can't I do echo "Usage: $0:t" as the csh manual page seems to claim? (i.e. it doesn't say I *can't* do that!) What DOES work, however, is set zero = $0 echo "Usage: $zero:t" Any ideas, anyone?? > >> bill davidsen (wedu@ge-crd.arpa) >> {uunet | philabs | seismo}!steinmetz!crdos1!davidsen >> "Stupidity, like virtue, is its own reward" -me > >Matthew C. Squires, local GNUisance >squires@eecs.nwu.edu OR {ihnp4,oddjob,gargoyle,chinet}!nucsrl!squires Geoff ------------------------------------------------------------ Geoff Rimmer, Computer Science, Warwick University, UK. maujd@uk.ac.warwick.opal "I report the news as it's seen in my country" - CNN ------------------------------------------------------------