I'm having issues with iterating through an array passed as an argument to a function in my bash script. I thought the answer to this question would solve my issue, but I'm getting a different error and the question is very old, so I thought I should ask a new question.
I am trying to convert this code to a function, so I can pass different parameters:
EX='WT'
declare -a SCN=('fq1'
'fq2'
'fq3' )
for i in "${SCN[@]}"; do
echo $i
echo $EX'_'$i
done
This prints
fq1
WT_fq1
fq2
WT_fq2
fq3
WT_fq3
What I have tried:
function myfx(){
echo $1
MYNOR=("${!2}")
for i in ${MYNOR[@]}; do
echo $i
echo $1'_'$i
done
}
myfx $EX $SCN[@]
Unfortunately, all I get from this is
WT
It doesn't seem to be executing the statements within the loop.
${!a}. In it, it is an indirect reference If the first character of parameter is an exclamation point (!), it introduces a level of variable indirection.