#!/bin/bash
PRE_SET_NUM=8
echo "Input a number between 1 and 10"
while read guess
do
if [[ $guess -eq $PRE_SET_NUM ]];then
echo "You get the right number"
exit
else
echo "Wrong,try again"
fi
done
脚本中 : while read guess 语句 read guess 执行后不是返回 0 吗?为什么会继续往下执行呢?再看这个例子:
read test;echo $? #这条语句在终端执行时(读入任意字符)会返回0,不是和 while read guess 矛盾了吗?请教。。。
ringcui2014 于 2014-11-21 22:19:46发表:
这个脚本有问题吧,while read的用法一般是这样的:
while read var
do
command1
command2
...
done < file
你的脚本没有文件输入
cosxeb 于 2014-11-09 08:52:00发表:
帮顶下