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}
'$' symbol is used for parameter expansion also that has various types of uses in bash. Parameter expansion can be used to modify, expand or replace the value of the parameter. The optional braces are used with the variable when using variable parameter expansion, such as 'echo ${myvar}'.
It means "Use the second argument if the first is undefined or empty, else use the first". The form "${2-${1}}" (no ':') means "Use the second if the first is not defined (but if the first is defined as empty, use it)". Copy link CC BY-SA 2.5.
The length in characters of the expanded value of parameter is substituted. If parameter is ' * ' or ' @ ', the value substituted is the number of positional parameters. If parameter is an array name subscripted by ' * ' or ' @ ', the value substituted is the number of elements in the array.
You don't have to use any special character before the variable name at the time of setting value in BASH like other programming languages. But you have to use '$' symbol before the variable name when you want to read data from the variable.
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}"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With