- $()与${}区别
简单描述:
1) $()
bash shell 中:$( )与` ` (反引号)都是用来做命令替换用(command substitution)的;
在其他shell中$()不确定(待展开),而``反引号移植性强。
2) ${} 变量替换
扩展:知道并识别${}中的#,%,/的用法
#是去掉左边(在鉴盘上#在$之左边)
%是去掉右边(在鉴盘上%在$之右边)
单一符号是最小匹配﹔两个符号是最大匹配。
inside ${ ... } Action taken
-----------------------
name:number:number Substring starting character, length
#name Return the length of the string
name#pattern Remove (shortest) front-anchored pattern
name##pattern Remove (longest) front-anchored pattern
name%pattern Remove (shortest) rear-anchored pattern
name%%pattern Remove (longest) rear-anchored pattern
name/pattern/string Replace first occurrence
name//pattern/string Replace all occurrences
以上摘自<bash cookbook> CH5.18 ,Table5-1
----------------------
更多见: http://blog.csdn.net/ancky_zhang/article/details/4584242
其中command1 `command2 /`command3/` `错误,应该为command1 `command2 \`command3\` `