${}: 数据“内容”删除,替换;{}: 列表
1. 条件测试: test
=~:正则匹配
2. if/then/elif/else/fi
#!/bin/bashecho "Is it ok? yes or no"read YES_OR_NOif [ "$YES_OR_NO" = "yes" ]; then
echo "is ok"
elif [ "$YES_OR_NO" = "no" ]; then
echo "is not ok"
else
echo "sorry"
exit
fi
3. case/esac
#!/bin/bashecho "is it morning" read YES_OR_NO case "$YES_OR_NO" in
yes|y|Yes|YES)
echo "good morning"
echo "good morning"
echo "good morning"
echo "good morning"
echo "good morning";;
[nN]*)
echo "good afternoon";;
*)
echo "sorry"
exit ;;
esac
4. for/do/done
#!/bin/bashfor Fruit in apple banana pear;do
echo "I like $Fruit"
done
#!/bin/bashfor read_parm in $@;do
echo $read_parm
done
5. while/do/done
#!/bin/bashecho "Enter passward: "
read key
while [ "$key" != "douzi" ];do
echo "Sorry, try again"
read key
done
#!/bin/bashCounter=
while [ "$Counter" -lt ];do
echo "Here we go again"
Counter=$(($Counter+))
done
- 采用 i++
#!/bin/baship=115.239.210.27i=
while [ $i -le ]
do
ping -c1 $ip &>/dev/null
if [ $? -eq ];then
echo "$ip is up.."
fi
let i++ done
6. break和continue
#!/bin/bashcnt=
while [ $cnt -lt $# ];do
if [ $cnt -eq ];then
echo "this is break"
break
fi
cnt=$(($cnt+))
done
7. tee
功能:tee命令把结果输出到标准输出,另一个副本输出到相应文件