0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

配列の内容を改行して出力する

Posted at

背景・目的

  • ShellScripの実行内容がわかるように対象となった値を出力したかった
  • 対象は配列で管理していたのでわざわざループせずに出力したかった

コマンド

# 配列作成
$ array=('aaa' 'bbb' 'ccc')

# 区切り文字指定
$ IFS=$'\n'

# 出力
$ echo "${array[*]}"

ミニ解説

  • "${array[*]}"は配列の内容を1つの文字列として連結して出力する
  • デフォルトの区切り文字は空白なのでIFS=$'\n'で区切り文字に改行を指定することで要素ごとに改行して出力できる

補足

  • IFS=$'\n'$は必須
  • ${array[@]}とは違うので間違えないように
  • "${array[*]}"のダブルクオートは必須
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?