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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -