linux - while read bash array (not into) -
i'm trying use array while read
, entire array output @ once.
#!/bin/bash declare -a arr=('1:one' '2:two' '3:three'); while read -e ; echo $it done <<< ${arr[@]}
it should output each value separately (but doesn't), maybe while read isn't hot ticket here?
for case, easier use for
loop:
$ declare -a arr=('1:one' '2:two' '3:three') $ in "${arr[@]}"; echo $it; done 1:one 2:two 3:three
the while read
approach useful (a) when want read data file, , (b) when want read in nul or newline separated string. in case, however, have data in bash
variable , for
loop simpler.
Comments
Post a Comment