目录
任务描述
本关任务:利用if else语句编写程序实现输入数字123,输出“you input is 123”;输入其他数字,输出“you input is not 123”。
相关知识
为了完成本关任务,你需要掌握:if语句的基本格式。
案例演示1
if语句的使用需要注意判断符号[]
的书写要求。
read -p "请回答(y/n):" answer
if [ "$answer" == "y" ] || [ "$answer" == "Y" ] ; then
echo "是"
else
echo "否“
fi
编程要求
根据要求,在右侧编辑器补充代码,利用if else语句编写程序实现输入数字123,输出“you input is 123”;输入其他数字,输出“you input is not 123”。
测试说明
平台会对你编写的代码进行测试:
测试输入:123
; 预期输出:you input is 123
测试输入:456
; 预期输出:you input is not 123
代码
#!/bin/bash
read -p "please input a number:" number
# echo "$number"
# 请在此处编辑您的代码
#********** Begin **********#
if [ "$number" == "123" ] ; then
echo "you input is 123"
else
echo "you input is not 123"
fi
#********** End **********#