Xref: utzoo comp.unix.questions:27364 comp.unix.shell:1025 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!hp4nl!star.cs.vu.nl!maart From: maart@cs.vu.nl (Maarten Litmaath) Newsgroups: comp.unix.questions,comp.unix.shell Subject: Re: Variable substitition Message-ID: <8419@star.cs.vu.nl> Date: 4 Dec 90 21:30:28 GMT References: <1990Nov30.092424@cs.utwente.nl> <8393@star.cs.vu.nl> Sender: news@cs.vu.nl Reply-To: maart@cs.vu.nl (Maarten Litmaath) Organization: VU Dept. of Computer Science, Amsterdam, The Netherlands Lines: 34 A slight improvement of my original solution. # How to get the last argument of a shell script reliably. # If you are sure the number of arguments is in [1-9], you can use this: # # eval last=\$$# # # The general solution works for ANY number of arguments. set a b c d e f g h i j k l m -n # For example. case $# in 0) # So the user tried to be funny; let's give him a little surprise. exec kill -SYS $$ ;; [1-9]) eval last=\$$# ;; *) last=` n=$# set '' ${1+"$@"} shift $n echo -n "$1" ` esac echo "last=|$last|" -- Q: "Is there a newsgroup for astrology/para-normal?" A: "Why don't you consult the stars and find out ??" -- Phil Watson