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

Geoff Rimmer maujd at warwick.UUCP
Tue Jun 21 22:56:29 AEST 1988


In article <3680037 at eecs.nwu.edu> squires at eecs.nwu.edu (Matthew Squires) writes:
>> 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)...
>
>	[ /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 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


Geoff
	------------------------------------------------------------
	Geoff Rimmer, Computer Science, Warwick University, UK.
			maujd at uk.ac.warwick.opal

	"I report the news as it's seen in my country" - CNN
	------------------------------------------------------------



More information about the Comp.unix.questions mailing list