4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

変数展開の中で変数を使う

Posted at
name="aereal"
echo ${name:+"[${name}]"} # -> (aereal)

${name:+replace}$name が空 (non-null) でなければ値を replace で置き換える。

replace は文字列として評価する必要があるのでダブルクォートで囲む必要がある。

例のコードを評価すると、$name が空であれば何も出力せず、なにか値があればブラケット ([]) で囲んで出力する、という風になる。

4
4
2

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
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?