1. 程式人生 > >shell指令碼日常練習

shell指令碼日常練習

請寫一個ping 公司內網的指令碼

#!/bin/bash
for i  in  `seq  254`
do 
    ping -c2  -i0.1   -W1  172.18.1.$i   &> /dev/null
    if [ $? -eq 0 ];then  
    		echo  " 172.18.1.$i  開機狀態"
    else 
    		echo   " 172.18.1.$i  關機狀態"
    fi
    done

9*9 乘法表的指令碼

for i in  `seq 9`
do 
	for j  in `seq $i`
	do
		echo -n "$i*$j =$[i*j] "
	done
	echo 
done 

猜隨機數的指令碼

num=$[RANDOM%100+1]
i=0
while :
do
	read -p  "請輸入:" cai
	let i++
	if [ $cai -eq $num ];then
		echo "恭喜,你猜了$i 次"
		exit 
	elif  [ $cai -gt $num ];then
		echo "猜大了"
	else 
		echo "猜小了"
fi
done

case $1 in
redhat)
echo “fedora”;;
fedora)
echo “redhat”;;
*)
echo “usage…”;;
esac