linux-tutorial/codes/linux/shell-demos/statement/ifDemo.sh

28 lines
378 B
Bash
Raw Normal View History

2017-11-17 17:06:52 +08:00
#!/usr/bin/env bash
if [[ -z $1 ]]; then
echo "please input first param";
exit
fi
if [[ -z $2 ]]; then
echo "please input second param";
exit
fi
2019-02-22 19:24:00 +08:00
if [[ $1 > $2 ]]; then
echo "\$1 > \$2";
elif [[ $1 < $2 ]]; then
echo "\$1 < \$2";
2017-11-17 17:06:52 +08:00
else
echo "\$1 != \$2";
fi
# execute: ./ifDemo.sh abc abc
# output:
# $1 == $2
# execute: ./ifDemo.sh abc ab
# output:
# $1 != $2