How to initialize a bash array with output piped from another command? [duplicate]

You can execute the command under ticks and set the Array like,

ARRAY=(`command`)

Alternatively, you can save the output of the command to a file and cat it similarly,

command > file.txt
ARRAY=(`cat file.txt`)

Or, simply one of the following forms suggested in the comments below,

ARRAY=(`< file.txt`)
ARRAY=($(<file.txt))

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)