测试单反斜杠``和$()在shell中的区别:
a="Te st"或者a='Te st'
echo $b
结果:Te st
echo $c
结果:Te\ st
d=`echo "$a" | sed 's/ /\\\\ /g'`
echo $d
结果:Te\ st
eval echo $d
结果:Te st
所以终上所述:
单反引号的执行结果就相当于在第一次执行结果的基础之上又执行了一次eval,
而$()只是相当于单反引号的第一次结果。
### From da niu ###
- Prefer =$()= instead of =``= since
- The former is easier to be spotted.
- The former dose not incur an extra level of escaping. Therefore, is more
straightforward.
#+BEGIN_EXAMPLE
$ a=$(echo 'a b' | sed 's/ /\\t/'); echo "$a"
a\tb
$ a=`echo 'a b' | sed 's/ /\\t/'`; echo "$a"
a b
$ a=`echo 'a b' | sed 's/ /\\\\t/'`; echo "$a"
a\tb
#+END_EXAMPLE