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

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -