一些技巧:
前截取字符串:${1##*.}
后截取字符串:${1%%.*}
截取字符串: ${str:pos:len} 类似于substr
[oracle@vmlinux .aa]$ export str=abc.tar
[oracle@vmlinux .aa]$ echo ${str##*.}
tar
[oracle@vmlinux .aa]$ echo ${str%%.*}
abc
算术运算(整数):echo $((n1+n2))
[oracle@vmlinux .aa]$ echo $((100+200))
300
[oracle@vmlinux .aa]$ export n1=100
[oracle@vmlinux .aa]$ export n2=200
[oracle@vmlinux .aa]$ echo $((n1+n2))
300
支持加减乘除,不支持浮点运算。
shell学习的一些网站:
http://www.linuxsir.org/main/?q=node/135
http://www.orczhou.com/index.php/2009/09/linux-shell-script/
- http://www.ibm.com/developerworks/cn/linux/shell/bash/bash-1/index.html
- http://www.ibm.com/developerworks/cn/linux/shell/bash/bash-2/index.html
- http://www.ibm.com/developerworks/cn/linux/shell/bash/bash-3/index.html
- http://www.linuxsir.org/main/?q=node/135
- BASH Programming ? Introduction HOW?TO