home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.shell
- Path: sparky!uunet!coplex!trebor!root
- From: root@trebor.uucp (Bob Stockler)
- Subject: Re: how to get the last pos. parameter in ksh?
- Organization: Bob Stockler
- Date: Wed, 11 Nov 1992 01:07:20 GMT
- Message-ID: <1992Nov11.010720.498@trebor.uucp>
- References: <KURO.92Nov9112643@vodka.Eng.Sun.Com>
- Lines: 25
-
- kuro@vodka.Eng.Sun.Com (Teruhiko Kurosaka) writes:
-
- >How can I write a ksh function to examine the last parameter (argument)
- >of the command line? I.e., I'd like to know how to access argv[argc-1].
-
- Off the top of my head, this oughta do something like you're after:
-
- function getlastarg
- {
- shift $(( $# - 1 ))
- print $1
- }
- print $(getlastarg $@)
-
- As I see it, the call of the function passes all of the command line
- arguments (or otherwise-set positional parameters) to the function
- "getlastarg", which (in my version of the KornShell) uses them as
- local (to it) positional parameters. After shifting to the last one,
- the function returns it, which we read by command substitution. The
- parent shell's positional parameters haven't been disturbed.
-
- I am just learning the mysteries of the KornShell, so am posting this -
- rather than responding to you via email - in hopes to learn more about
- the KorenShell from those more experienced and knowledgeable.
-
-