4
1

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 1 year has passed since last update.

スペースがある文字列を変数にする場合 シェルスクリプト

Posted at

スペースのある変数をそのままシェルスクリプトのif文等で使うと文法エラーになる。

「 [: too many arguments」みたいに。

以下のサイトを参考に
https://ritchiekotzen.hatenablog.com/entry/20090430

if文で使用するとき回避方法は2つある。

1.変数自体をダブルコーテーションで囲む。
  "$STATUS"

2.if文のカッコを2重カッコにする
[[ (Ended immediately) = (\R\u\n\n\i\n\g) ]]

なんでif文の中で2重カッコにしているのか不明だったが
そういうことってわかった。

4
1
1

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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?