RHEL8 Bash配列の要素でjoinするサンプル

環境
RHEL8.6

構文
配列名=(xxxx)
変数名="$(IFS=,; echo “${配列名[*]}")"

使用例

arrA=(a "s t" $'d\ne' f)

# join実行
strA="$(IFS=,; echo "${arrA[*]}")"

# 確認
echo "=== join前 ==="
for v in "${arrA[@]}"; do
  echo "[$v]"
done
echo "=== join後 ==="
echo "$strA"

実行結果
=== join前 ===
[a]
[s t]
[d
e]
[f]
=== join後 ===
a,s t,d
e,f

AlmaLinux

Posted by arkgame