< BACK

Bash tips, tricks and code snippets

Read output of command into an array

arr=()
while IFS= read -r line; do
    arr+=( "$line" )
done < <( some_command )

also on Bash >= 4

mapfile -t arr < <( some_command )

NOTE:

Don’t use the following (it’s broken) - see here for an explanation:

my_array=( $(my_command) )