help-bash
[Top][All Lists]
Advanced

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

[Help-bash] inconsistency in expansions


From: Bill Gradwohl
Subject: [Help-bash] inconsistency in expansions
Date: Sun, 6 May 2012 13:24:09 -0600

set -- "The cat " "ate the " "canary"
echo $#
x=$#
declare string
string="${*%${$#}}"
echo $string
string="${*%${$x}}"
echo $string
string="${*%${3}}"
echo $string

Produces:

address@hidden ycc# ./tst
3
The cat ate the canary
./tst: line 7: ${$x}: bad substitution
The cat ate the canary
The cat ate the


I expected all of them to work.

Why does bad substitution only occur for $x and not for $#?

$# version is ignored - doesn't work and doesn't produce an error message.

Aren't expansions done from the inside out?

--
Bill Gradwohl


reply via email to

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