关于一个脚本出现的问题!

系统安装、升级讨论
版面规则
我们都知道新人的确很菜,也喜欢抱怨,并且带有浓厚的Windows习惯,但既然在这里询问,我们就应该有责任帮助他们解决问题,而不是直接泼冷水、简单的否定或发表对解决问题没有任何帮助的帖子。乐于分享,以人为本,这正是Ubuntu的精神所在。
回复
valhelsing
帖子: 200
注册时间: 2007-01-03 17:10

关于一个脚本出现的问题!

#1

帖子 valhelsing » 2007-08-28 10:03

我最近在学习脚本,其中有一个脚本的内容如下:

#!/bin/bash
declare -i i
declare -i s
while [ "$i" != "101" ]
do
s=s+i
i=i+1
done
echo "the result is ==> $s"

然后我运行此脚本结果SHELL提示说:declare:no found

这是什么原因呢?
头像
iblicf
帖子: 3766
注册时间: 2007-01-15 17:15

#2

帖子 iblicf » 2007-08-28 10:15

no problem
valhelsing
帖子: 200
注册时间: 2007-01-03 17:10

#3

帖子 valhelsing » 2007-08-28 10:37

可我运行的时候确实是出现了 declare:no found!~
头像
bones7456
帖子: 8495
注册时间: 2006-04-12 20:05
来自: 杭州
联系:

#4

帖子 bones7456 » 2007-08-28 10:42

你确定头上的:
#!/bin/bash
没有写成:
#!/bin/sh
或者是:
#!/bin/dash
关注我的blog: ε==3
valhelsing
帖子: 200
注册时间: 2007-01-03 17:10

#5

帖子 valhelsing » 2007-08-28 10:45

确定~!~
头像
bones7456
帖子: 8495
注册时间: 2006-04-12 20:05
来自: 杭州
联系:

#6

帖子 bones7456 » 2007-08-28 10:50

代码: 全选

lily@LLY:~/test$ ll /bin/bash 
-rwxr-xr-x 1 root root 700560 2007-04-11 07:32 /bin/bash
lily@LLY:~/test$ cat ttt
#!/bin/bash
declare -i i
declare -i s
while [ "$i" != "101" ]
do
s=s+i
i=i+1
done
echo "the result is ==> $s" 
lily@LLY:~/test$ ./ttt
the result is ==> 5050
lily@LLY:~/test$ 
我这边正常,无语了。
关注我的blog: ε==3
valhelsing
帖子: 200
注册时间: 2007-01-03 17:10

#7

帖子 valhelsing » 2007-08-28 11:00

那我在试试!~
回复