In shell script, storing an output into an array inside case statement -


i wanted store output array in shell script called inside case statement. running on bash version 3.2.39. windriver linux.

the command used files_array_out=( $(ls | grep test) )

this command works fine , stores output array, when defined outside case statement. if same command called inside case statement, output not stored in array. stores output single variable new line in between.

ex: created 3 files test1, test2 , test3. , example used

#!/bin/bash

#####outside case statement

files_array_out=( $(ls | grep test) ) echo "outside case statement: first element of test files ${files_array_out[0]}"

# inside case statement

echo "enter 1"

ifs="";read a

case "$a" in "1") files_array=( $(ls | grep test) ) echo "inside case statement: first element ${files_array[0]}" ;; esac


output got after running is: sh check.sh outside case statement: first element of test files test1 enter 1 1 inside case statement: first element test1 test2 test3

could me problem. why output different inside , outside case statement when same command used?. how same output when command used inside case statement?


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -