maujd@warwick.UUCP (Geoff Rimmer) (06/21/88)
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 ------------------------------------------------------------
leo@philmds.UUCP (Leo de Wit) (06/26/88)
In article <709@ubu.warwick.UUCP> maujd@warwick.UUCP (Geoff Rimmer) writes: > [other stuff deleted]... >cat /etc/passwd | sed "s/:[^:]*:[^:]*:[^:]*:/ /" | sed "s/[,:].*//" | sort > ^^TAB^^ >--------------------------------------------------------------------- > (BTW, anyone got any improvements on this 'sed' line?) >--------------------------------------------------------------------- You COULD of course use awk (using IFS) ... but, assuming you're as devoted a sed worshipper as I am, yes, I've got an improvement: Don't use the cat; sed can open the file or even the shell can open it for sed (saves a process). Don't use sed twice; one is just as good (even faster). So the result is: sed -e "s/:[^:]*:[^:]*:[^:]*:/ /" -e "s/[,:].*//" /etc/passwd | sort Now maybe even the sed could be improved upon ...? Leo.
maart@cs.vu.nl (Maarten Litmaath) (06/27/88)
In article <709@ubu.warwick.UUCP> maujd@warwick.UUCP (Geoff Rimmer) writes:
\cat /etc/passwd | sed "s/:[^:]*:[^:]*:[^:]*:/ /" | sed "s/[,:].*//" | sort
\ ^^TAB^^
\---------------------------------------------------------------------
\ (BTW, anyone got any improvements on this 'sed' line?)
How about:
sed 's/:[^:]*:[^:]*:[^:]*:\([^,:]*\).*/ \1/' /etc/passwd | sort
--
I'd rather live in Russia |Maarten Litmaath @ Free U Amsterdam:
than in South-Africa... |maart@cs.vu.nl, mcvax!botter!ark!maart