I am currently working on a script that receives input from stdin, and then loads the input line by line into an array for further processing. Although the array works fine if I set the array name directly, I cannot get the array part to work properly when I attempt to use a variable as the array name, the code itself is below:
input=$(</dev/stdin)
# back up the field separator for later
OLDIFS=$IFS
# set the field separator to newline
IFS=$'\n'
# populate an array from that variable, as delimited by the IFS
lines=($input)
and this is what I have tried for setting the array name as a variable
arrayname="something"
eval $arrayname=($input)
but unfortunately when I go to run this, I get the following error:
./f.sh: line 53: syntax error near unexpected token `('
./f.sh: line 53: ` eval $arrayname=($input)'
having said all of this, I was wondering if anyone would know what I could do to make this work correctly? thanks!