Shell脚本IF条件判断和判断条件总结
最新推荐文章于 2024-04-12 14:24:04 发布
#!/bin/sh
SYSTEM=`uname -s`
if
[ $SYSTEM =
"Linux"
] ; then
echo
"Linux"
elif [ $SYSTEM =
"FreeBSD"
] ; then
echo
"FreeBSD"
elif [ $SYSTEM =
"Solaris"
] ; then
echo
"Solaris"
else
echo
"What?"
fi
#!/bin/bash
read -p
"please input a score:"
score
echo -e
"your score [$score] is judging by sys now"
if
[
"$score"
-ge
"0"
]&&[
"$score"
-lt
"60"
];then
echo
"sorry,you are lost!"
elif [
"$score"
-ge
"60"
]&&[
"$score"
-lt
"85"
];then
echo
"just soso!"
elif [
"$score"
-le
"100"
]&&[
"$score"
-ge
"85"
];then
echo
"good job!"
else
echo
"input score is wrong , the range is [0-100]!"
fi
#!/bin/sh
today=`date -d yesterday +%y%m%d`
file=
"apache_$today.tar.gz"
cd /home/chenshuo/shell
if
[ -f
"$file"
];then
echo
"OK"
else
echo
"error $file"
>error.log
mail -s
"fail backup from test"
loveyasxn924
@126
.com <error.log
fi
#!/bin/bash
WEEKOFFSET=$[ $(date +
"%V"
) %
2
]
if
[ $WEEKOFFSET -eq
"0"
]; then
echo
"Sunday evening, put out the garbage cans."
| mail -s
"Garbage cans out"
your
@your_domain
.org
fi