[Top][All Lists]

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

Re: [Help-bash] inconsistency in expansions

From: Greg Wooledge
Subject: Re: [Help-bash] inconsistency in expansions
Date: Mon, 7 May 2012 08:29:08 -0400
User-agent: Mutt/

On Sun, May 06, 2012 at 01:24:09PM -0600, Bill Gradwohl wrote:
> set -- "The cat " "ate the " "canary"
> echo $#
> x=$#
> declare string
> string="${*%${$#}}"

What the bloody hell is that supposed to DO?

> I expected all of them to work.

What is "work"?

Seriously, tell us what you THINK it is supposed to do.  Better yet,
simply tell us what you WANT to do, and do not write any code, and we
will tell you how to do it.  Or we will tell you that it is not possible.

Are you trying to print the Nth positional parameter, where N is an
integer stored in some other variable?  Then do this:

set -- "the cat " "ate the " "canary"
echo "${!n}"

Or use an actual array:

echo "${array[n]}"

reply via email to

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