In Bash, I'm reading out fields from a line into an array. Let me stress that performance is an issue, so I can't afford anything that spawns subprocesses.
To make the code more readable, I want the fields into variables: $width
is more readable than ${array[0]}
. I have to manually set each and every variable, like this, which is a lot of repetition:
while read line; do
array=($line)
width=${array[0]}
height=${array[1]}
size=${array[2]}
date=${array[3]}
time=${array[4]}
# use $width, $height, etc. in script
done < file
Is there any compact way to do it, like the list
directive in PHP?
list($width, $height, $size, $date, $time) = $array;
line
being set? – jesse_b Apr 05 '18 at 17:18array=($line)
, unless you alsoset -f
– glenn jackman Apr 05 '18 at 20:23