1.for
练习
#!/bin/bash
for AA in {1..10}
do
ping -c1 172.25.254.$AA &>/dev/null && {
echo 172.25.254.$AA
}
done
2.while
3.until
4.if
#!/bin/bash
CHECK()
{
read -p "Please input filename:" FILENAME
if [ "$FILENAME" = "exit" ]
then
exit
elif [ ! -e "$FILENAME" ]
then
echo "$FILENAME is not exist."
elif [ -L "$FILENAME" ]
then
echo "$FILENAME is link."
elif [ -f "$FILENAME" ]
then
echo "$FILENAME is common file."
elif [ -d "$FILENAME" ]
then
echo "$FILENAME is directory."
elif [ -S "$FILENAME" ]
then
echo "$FILENAME is socket."
elif [ -b "$FILENAME" ]
then
echo "$FILENAME is block."
elif [ -c "$FILENAME" ]
then
echo "$FILENAME is char."
fi
CHECK
}
CHECK
5.case
#!/bin/bash
case $1 in
disk)
watch -n 1 df -h
;;
memory)
watch -n 1 free -m
;;
upload)
watch -n 1 uptime
;;
esac
6.expect
7.break,continue,exit
continue 终止此次循环提前进入下个循环
break 终止当前所在语句所有动作进行语句外的其他动作
exit 脚本退出
continue
#!/bin/bash
for I in {1..10}
do
if [ "$I" = "4" ]
then
echo lucky number
continue
fi
echo $I
done
echo end
break
exit