21

Possible Duplicate:
Can ${var} parameter expansion expressions be nested in bash?

Is it possible to nest the shell parameter expansion (${})?

If I want to do something like this:

foo=( 1 2 3 4 5 )
echo ${${foo[@]/3/bar}:1}
codeforester
  • 39,467
  • 16
  • 112
  • 140
Tyilo
  • 28,998
  • 40
  • 113
  • 198

2 Answers2

19

No, you can't. (You can in zsh, but not in bash, ksh or other shells.)

You need to use an intermediate variable:

foo=( 1 2 3 4 5 )
tmp=("${foo[@]/3/bar}")
echo "${tmp[@]:1}"
Gilles 'SO- stop being evil'
  • 104,111
  • 38
  • 209
  • 254
9

As far as I know, it is not possible to nest shell parameter expansion. I'm afraid you'll have to figure out another way of achieving what you need. If you post the code, maybe we can help you.

EdoDodo
  • 8,220
  • 3
  • 24
  • 30