-d 判斷目錄
-f 判斷普通文件
-e 文件是否存在
[ -d /tmp ] && echo "OK" || echo "NO"
[ -f /tmp/test.txt ] && echo "OK" || echo "NO"
[ -e /tmp/test.txt ] && echo "OK" || echo "NO"
注意 后面的&& 和|| 順序 必須是&& 在前
-f 判斷普通文件
-e 文件是否存在
[ -d /tmp ] && echo "OK" || echo "NO"
[ -f /tmp/test.txt ] && echo "OK" || echo "NO"
[ -e /tmp/test.txt ] && echo "OK" || echo "NO"
注意 后面的&& 和|| 順序 必須是&& 在前
2016-09-21
腳本包含服務名時,寫成ps aux | grep apache |grep -v grep,就算腳本名字是httpd,也沒事,除非故意寫成相沖突的
2016-09-18
老師沒有考慮num2=0的情況,請把 sum=$(( $num1 / $num2 )) 替換成下面:
if [ $num2 != 0 ]
then
sum=$(( $num1 / $num2 ))
else
echo "請輸入正確的num2:"
exit 12
fi
不用謝!
if [ $num2 != 0 ]
then
sum=$(( $num1 / $num2 ))
else
echo "請輸入正確的num2:"
exit 12
fi
不用謝!
2016-09-17
#!/bin/bash
test=$(df -h | grep sda5 | awk '{print $5}' |cut -d "%" -f 1)
if [ "$test" -ge "10" ]
then
echo "ROM:我要報警啦!"
fi
test=$(df -h | grep sda5 | awk '{print $5}' |cut -d "%" -f 1)
if [ "$test" -ge "10" ]
then
echo "ROM:我要報警啦!"
fi
2016-09-17
#!/bin/bash
read -t 30 -p "pls enter your username:" username
echo -e "\n"
read -t 20 -s -p "pls enter your passwd:" passwd
echo -e "\n"
if [ "$username" == "root" ];then
if [ "$passwd" == "789" ];then
echo "OK!!"
else
echo "Your passwd is wrong!!"
fi
else
echo "Your username is wrong!!"
fi
read -t 30 -p "pls enter your username:" username
echo -e "\n"
read -t 20 -s -p "pls enter your passwd:" passwd
echo -e "\n"
if [ "$username" == "root" ];then
if [ "$passwd" == "789" ];then
echo "OK!!"
else
echo "Your passwd is wrong!!"
fi
else
echo "Your username is wrong!!"
fi
2016-08-29