Store array output to comma separated list in bash scripting Store array output to comma separated list in bash scripting shell shell

Store array output to comma separated list in bash scripting


If you have an array like this:

$ declare -p arrdeclare -a arr='([1]="abc" [2]="def")'

You can display it in comma-separated format:

$ (IFS=,; echo "{${arr[*]}}"){abc,def}

That output can be saved in a shell variable using command substitution:

$ var=$(IFS=,; echo "{${arr[*]}}")$ echo "$var"{abc,def}