How to concatenate arrays in bash?

First, to read your list into an array, one entry per line:

readarray -t countries

…or, with older versions of bash:

# same, but compatible with bash 3.x; || is to avoid non-zero exit status.
IFS=$'\n' read -r -d '' countries || (( ${#countries[@]} ))

Second, to duplicate the entries, either expand the array to itself three times:

countries=( "${countries[@]}" "${countries[@]}" "${countries[@]}" )

…or use the modern syntax for performing an append:

countries+=( "${countries[@]}" "${countries[@]}" )

Leave a Comment

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