#!/bin/bash
#fitest
if [ "10" -lt "12" ]
then
echo "yes,10 is less than 12"
fi
#!/usr/bash
echo -n "Please enter your name:" // -n 不换行
read NAME // 读输入名称到变量
if [ "$NAME" == "" ];then
echo "You did not enter your name" //输入为空提示
else
echo "Your name is ${NAME}"
fi
#!/bin/bash
#ifcp
echo -n "Enter your name:"
read NAM
#if [ -z $NAME ] || // -z the length of STRING is zero(为空)
if [ "$NAME" = "" ];then // = 或者 == 都可以
echo "You did not enter a name"
elif [ $NAME = "root" ]; then
echo "Hello root"
elif [ $NAME = "beyes" ]; then
echo "Hello beyes"
else
echo "you are not root or beyes,but hi, $NAME"
fi
#!/bin/bash
echo "Is it morning? Please answer yes or no"
read timeofday
if [ $timeofday = "yes" ]
then
echo "Good moring"
elif [ $timeofday = "no" ]; then
echo "Good afternoon"
else
echo "Sorry, $timeofday not recognized. Enter yes or no"
exit 1
fi
exit 0
[beyes@localhost shell]$ ./check_elif.sh
Is it morning? Please answer yes or no
./check_elif.sh: line 6: [: =: unary operator expected
./check_elif.sh: line 10: [: =: unary operator expected
欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) | Powered by Discuz! X3.2 |