shell编程语法
if
#!/bin/bash
port=$(nmap -sT 127.0.0.1 |grep tcp |grep mysql |awk '{print $2}')
if [ "$port" == "open" ]
then
echo "$(date) mysql is ok !"
else
/etc/init.d/mysqld restart &> /dev/null
echo "wrong"
fi
case
#!/bin/bash
echo "you want to shanghai.please input 1"
read -t 30 -p "choise:" cho
case "$cho" in
"1")
echo "shanghai ready"
;;
"2")
echo "beijing ready"
;;
esac
for
#!/bin/bash
for i in 1 2 3 4 5
do
echo $i
done
cd /home/hzhw/sh
ls *.sh > ls.log
y=1
for i in $(cat ls.log)
do
echo $y
y=$(($y+1))
done
s=0
for(( i=1;i<=10;i=i+1 ))
do
s=$(($s+$i))
done
echo "$s"
while until until与while相反
#!/bin/bash
i=0
s=0
while [ "$i" -le 100 ]
do
s=$(($s+$i))
i=$(($i+1))
done
echo "$s"
#!/bin/bash
i=0
s=0
until [ "$i" -gt 100 ]
do
s=$(($s+$i))
i=$(($i+1))
done
echo "$s"
转载请注明原文地址:https://blackberry.8miu.com/read-39852.html