[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Referencing last positional variable

From: Francis Montagnac
Subject: Re: Referencing last positional variable
Date: 22 Mar 2002 07:51:11 GMT

In article <address@hidden>,
 address@hidden (Paul Jarc) writes:
>"Robert Mark Bram" <address@hidden> wrote:
>> I have a script in which I would like to access the last positional variable
>> directly (and I don't know how many paramaters will be issued).

>This sort of question would be better off on comp.unix.shell.
>eval "last=\$$#"

You can also use a specific construct of bash: indirect expansion.


>From the man page:

       If  the  first  character  of  parameter is an exclamation
       point, a level  of  variable  indirection  is  introduced.
       Bash  uses  the value of the variable formed from the rest
       of parameter as the name of the variable; this variable is
       then  expanded  and  that value is used in the rest of the
       substitution, rather than the value of  parameter  itself.
       This  is  known  as  indirect expansion.  The exception to
       this is the expansion of ${!prefix*} described below.

address@hidden, Tel: (33) 04 92 38 79 11, Bur: E106
INRIA Sophia, 2004, rte des Lucioles, B.P.93 - 06902 Sophia Antipolis Cedex

reply via email to

[Prev in Thread] Current Thread [Next in Thread]