-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