LoginSignup
0
1

More than 5 years have passed since last update.

bsh-クォーテーション

Last updated at Posted at 2019-03-02

bshのクォーテーションについて

bshではシングルクォーテーション(')とダブルクォーテーション(")で挙動が違います。
些細な違いですが、正しく把握することが重要です。

シングルクォーテーション(')

シングルクォーテションに囲まれた文字列の特殊文字は普通の文字と同じ扱いとなる。

echo 'today is `date`'
// today is `date`

ダブルクォーテーション(")

$,(バッククォート),\の三つの文字をエスケープしない。
それ以外の文字はエスケープする。

echo "today is `date`"
// today is 2019年 3月 2日 土曜日 09時16分06秒 JST

使い分け

囲んだ文字列の中でコマンドや変数を使用する場合は、ダブルクォーテーションを使用する。

ついでに、バッククォート(`)

バッククォートに囲まれたものは、コマンドとなる。

0
1
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
1