Double expansion of a parameter in Bash script -
this question has answer here:
i want expand parameter twice, , ${$param}
doesn't work.
for example, if set 2 variables file names , want loop through variables , expand file names:
inpf_1=input1.inp inpf_2=input2.inp # copy input files execution directory input_param in ${!inpf_*}; echo ${$input_param} done
how can access file names parameters in loop?
i.e., expand input1.inp
, input2.inp
.
you had almost: use "${!input_param}"
instead of ${$input_param}
.
the quoting doesn't in case, it's habit.
be aware of difference ${!inpf_@}
, – when used between double quotes – expands separate word each variable name, whereas "${!inpf_*}"
doesn't. want "${!inpf_@}"
. see difference:
$ var in "${!inpf_*}"; echo "$var"; done inpf_1 inpf_2 $ var in "${!inpf_@}"; echo "$var"; done inpf_1 inpf_2
see manual various parameter expansions.
Comments
Post a Comment