菜鸟教学
http://www.runoob.com/
shell表达式练习
http://www.runoob.com/try/runcode.php?filename=helloworld&type=bash
#!/bin/bash
echo "==========begin=========="
name="mi"
echo ${name} #变量输出时使用大括号是好习惯
str="hello,u r \"$name\"!" #转义字符“\”
echo ${str}str1="hello,"$name"!" #两种写法
str2="hello,${name}!" #注意单引号里面不能带变量或转义字符,双引号里才可以
echo $str1 $str2
echo "length is ${#str1}" #“#”查出变量长度
echo "${str1:2:7}" #字符串切片
echo "===========end==========="
输出如下:
==========begin==========
mi
hello,u r "mi"!
hello,mi! hello,mi!
length is 9
llo,mi!
===========end===========