Iterate through array given as argument to function in shell script
<p>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 <a href="https://stackoverflow.com/questions/6533364/passing-array-to-function-of-shell-script">this question</a> 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.</p>

<p>I am trying to convert this code to a function, so I can pass different parameters:</p>

<pre><code>EX='WT'
declare -a SCN=('fq1' 
'fq2'
'fq3' )

for i in "${SCN[@]}"; do
    echo $i
    echo $EX'_'$i
done
</code></pre>

<p>This prints</p>

<pre><code>fq1
WT_fq1  
fq2  
WT_fq2  
fq3  
WT_fq3
</code></pre>

<p>What I have tried:</p>

<pre><code>function myfx(){
echo $1
MYNOR=("${!2}")
for i in ${MYNOR[@]}; do
    echo $i
    echo $1'_'$i
done
}
myfx $EX $SCN[@]
</code></pre>

<p>Unfortunately, all I get from this is</p>

<pre><code>WT
</code></pre>

<p>It doesn't seem to be executing the statements within the loop.</p>