当前位置: 技术问答>linux和unix
我又来了,囧,还是脚本问题
来源: 互联网 发布时间:2016-12-13
本文导语: 初学者,诡异的问题,晕死 1 #!/bin/sh 2 #ifcounter 3 4 COUNTER=100 5 echo "Do you wish to change the counter value currently set at $COUNTER[y. 6 read ANS 7 if [ "$ANS"="y" ] || [ "$ANS"="Y" ] 8 then 9 ech...
初学者,诡异的问题,晕死
1 #!/bin/sh
2 #ifcounter
3
4 COUNTER=100
5 echo "Do you wish to change the counter value currently set at $COUNTER[y.
6 read ANS
7 if [ "$ANS"="y" ] || [ "$ANS"="Y" ]
8 then
9 echo "Enter a sensible value"
10 read VALUE
11 expr $VALUE + 10 > /dev/null 2>&1
12 STATUS=$?
13 echo "Status:$STATUS and VALUE:$VALUE"
14 if [ "$VALUE"="" -o "$STATUS"!="0" ]
15 then
16 echo "nothing or non-number" >&2
17 echo "Sorry now exiting..counter stays at $COUNTER" >&2
18 exit 1
19 fi
20 COUNTER=`expr $COUNTER + $VALUE`
21 echo "Counter now set to $COUNTER"
22 else
23 echo "Counter stays at $COUNTER"
24 fi
按书上来的哈,
以下是结果
Do you wish to change the counter value currently set at 100[y..n]
y
Enter a sensible value
1212
Status:0 and VALUE:1212
nothing or non-number
Sorry now exiting..counter stays at 100
应该是判断条件那出的问题,可是跟书上一样的,自己试验了好多版本都木有搞定,求教
PS:最近几天问题比较多,谢谢诸位大侠给俺的及时解答,搞定即结贴....攒的分估计这段时间全砸这个版块了
1 #!/bin/sh
2 #ifcounter
3
4 COUNTER=100
5 echo "Do you wish to change the counter value currently set at $COUNTER[y.
6 read ANS
7 if [ "$ANS"="y" ] || [ "$ANS"="Y" ]
8 then
9 echo "Enter a sensible value"
10 read VALUE
11 expr $VALUE + 10 > /dev/null 2>&1
12 STATUS=$?
13 echo "Status:$STATUS and VALUE:$VALUE"
14 if [ "$VALUE"="" -o "$STATUS"!="0" ]
15 then
16 echo "nothing or non-number" >&2
17 echo "Sorry now exiting..counter stays at $COUNTER" >&2
18 exit 1
19 fi
20 COUNTER=`expr $COUNTER + $VALUE`
21 echo "Counter now set to $COUNTER"
22 else
23 echo "Counter stays at $COUNTER"
24 fi
按书上来的哈,
以下是结果
Do you wish to change the counter value currently set at 100[y..n]
y
Enter a sensible value
1212
Status:0 and VALUE:1212
nothing or non-number
Sorry now exiting..counter stays at 100
应该是判断条件那出的问题,可是跟书上一样的,自己试验了好多版本都木有搞定,求教
PS:最近几天问题比较多,谢谢诸位大侠给俺的及时解答,搞定即结贴....攒的分估计这段时间全砸这个版块了
|
以前遇到楼主一样的困惑
结果调了半天。
结果调了半天。
|
犯错一次应该永远记住了。
|
细心加细心.
|
谨记!