てきとうなメモ

本の感想とか技術メモとか

Shellのシングルクォート

Shellのシングルクォートはエスケープしないのでシングルクォートの中でシングルクォートを利用することができない。

Enclosing characters in single-quotes ( '' ) shall preserve the literal value of each character within the single-quotes. A single-quote cannot occur within single-quotes.

Shell Command Language

例えば以下は内部のシングルクォートはエスケープされておらずシングルクォートを一旦とじてまた開いた状態になっている

$ echo 'That\'s right'
>

以下のようにすれば意図通りに出力できるんだけどもめんどい

$ echo 'That'\''s right'
That's right

Shellだけ特殊だなあと思っていたら、Perl6でもそんな提案があったみたい。以下のようなRFCがある。

Single quotes don't interpolate \' and \\

内部にシングルクォートを使えなくなるのではと一瞬思ったんだけども、q()で書けるよねと提案者は指摘している

You don't lose any functionality, as

   'don\'t implement this RFC, the benefits don\'t outweigh the confusion'

can still be written

   q(don't implement this RFC, the benefits don't outweigh the confusion)

which is actually less typing.

ただ、今のところ取り入れることにはなってないっぽいけど

I think hyperquotes will be possible with a declaration of your quoting rules, so we're not going to change the basic single-quote rules (except for supporting \q).

Apocalypse 2: Bits and Pieces - dev.perl.org