Shell Scripting

Dominic Mitchell dom at happygiraffe.net
Thu Mar 9 22:12:55 GMT 2000


On Thu, Mar 09, 2000 at 09:40:55PM +0000, Roger McCalman wrote:
> On Tue, Mar 07, 2000 at 09:31:19PM +0000, Gary Brewer wrote:
> > 
> > I thought it was ${$#} but in csh this just echoed a number not a string.
> > 
> > Any ideas?
> 
> checkout the man page on getopt. in general to get at args beyond $9
> you need to shift the others out of the way i.e. using sh
> 
> shift `expr $# - 1`
> last=$1

Most modern bourne/korn shell derivatives provide getopts instead
(including FreeBSD's /bin/sh).  It's a shell builtin, which saves a
process for each arg and has a bit nicer syntax.

Secondly, modern shells (like ours) have builtin arithmetic, so you
don't need expr as much.  You can recode the above example as:

shift $(( $# - 1 ))
last=$1

-Dom





More information about the Ukfreebsd mailing list