[问题]为什么我的shell在ubuntu 7.10下运行会有错误

sh/bash/dash/ksh/zsh等Shell脚本
回复
sharpshootor
帖子: 34
注册时间: 2007-12-23 12:22

[问题]为什么我的shell在ubuntu 7.10下运行会有错误

#1

帖子 sharpshootor » 2008-04-23 13:57

我脚本如下:
#!/bin/sh
echo "Input two interger number:"
foo=0
bar=0
declare -i foo
declare -i bar
read foo bar
select opsign in "+" "-" "*" "/" "exit"
do
break
done
if [[ $opsign = "exit" ]] ;then
exit 0
fi
if [[ $opsign = '/' && $bar = 0 ]] ;then
echo "divisor should not be 0"
exit 1
fi
echo "${foo}${opsign}${bar}=$(($foo $opsign $bar))"

exit 0
以上脚本我在windows下虚拟机redhat 9.0,运行没有任何问题,为什么同样的代码,我在ubuntu7.10(实机)下却出现如下错误:
yang@yang-desktop:~/test/finish$ ./cal.sh
Input two interger number:
./cal.sh: 5: declare: not found
./cal.sh: 6: declare: not found
1 2
./cal.sh: 8: select: not found
./cal.sh: 9: Syntax error: "do" unexpected
yang@yang-desktop:~/test/finish$
其中的“1 2”是输入的两数
本人刚学的,有好多不懂,望高手指点!!
头像
BigSnake.NET
帖子: 12522
注册时间: 2006-07-02 11:16
来自: 廣州
联系:

#2

帖子 BigSnake.NET » 2008-04-23 14:02

安装bash, 卸掉dash
^_^ ~~~
要理解递归,首先要理解递归。

地球人都知道,理论上,理论跟实际是没有差别的,但实际上,理论跟实际的差别是相当大滴。
头像
bones7456
帖子: 8495
注册时间: 2006-04-12 20:05
来自: 杭州
联系:

#3

帖子 bones7456 » 2008-04-23 14:31

dash害死多少人啊...不知道为什么ubuntu会用它.唉
关注我的blog: ε==3
thword
帖子: 119
注册时间: 2007-04-09 12:19

#4

帖子 thword » 2008-04-23 16:08

#!/bin/sh
改成
#!/bin/bash
回复