シェルスクリプトで外部コマンドを利用する場合の注意点
TL;DR
シェルスクリプトでbackquoteを見つけたら
オールドスタイルおじさんを探し、矯正させよう
When the old-style backquote form of substitution is used, backslash retains its lit- eral meaning except when followed by $, `, or \. The first backquote not preceded by a backslash terminates the command substitution. When using the $(command) form, all characters between the parentheses make up the command; none are treated specially.
#!/bin/bash #!/bin/bash a=`echo '\'` echo ${a} # \ b=`echo "\\"` echo ${b} # unexpected EOF while looking for matching `"' c=$(echo '\') echo ${c} # \ d=$(echo "\\") echo ${d} # \
参考
http://hyperpolyglot.org/unix-shells#cmd-subst-note
追記
csh系では動かないのでは?というご意見を頂いておりますが、csh系を利用されている方は基本的に強い意思を持って取り組まれているかと存じますので、わざわざ説明することはないと判断しております
— kenjiskywalker (@kenjiskywalker) November 10, 2014