一. 条件判断控制:
[ ] && ||
if
case
二. 循环控制:
while
utile
for
break
continue
三. 调试
bash -v ...
bash -vx ...
一.
1.
[ -f /bin/ls ] && /bin/ls
[ "$USER" = "root" ] && echo root 等价表示 [ $USER = root ] && ...双引号的作用见bash运算符
[ -x /etc/passwd ] && echo hello
[ -b /dev/sda ] && echo you have a scsi device 是否是块设备文件
[ -f /usr/sbin/httpd ] && echo httpd already installed
2.
if [ $AAA = mr ]
then
echo hello mr
elif [ $AAA = root ]
then
echo hello root
else echo someone else
fi
case $AAA in
mr)
echo hello mr
;;
root)
echo hello root
;;
*)
echo someone else
;;
esac
二.
1.
for aaa in 111 222 333 /etc/profile.d/*.sh
do
echo $aaa
done
2.
while 条件
do
指令
done
3.
until 条件
do
指令
done
4.
while true
do
read AAA
if [ "$AAA" = "quit" ]
then
break
fi
done
5.
函数的使用:
Myfunction()
{
}
取消函数的使用:
unset Myfunction()
类似的 unset i可以取消变量
阅读(2355) | 评论(0) | 转发(0) |