分页: 1 / 1

shell scripts 中declare 声明变量的问题?

发表于 : 2008-06-04 21:17
yangxiao
刚学shell scripts。
脚本:

declare -i s=0
5 for(( i=1 ;i<=100;i=i+1))
6 do
7 s=s+1;
8 done
9 echo "the count is ==> $s "
10

~


执行之后提示:
test11.sh: 4: declare: not found
test11.sh: 5: Syntax error: Bad for loop variable

Re: shell scripts 中declare 声明变量的问题?

发表于 : 2008-06-04 21:36
solcomo
yangxiao 写了:declare -i s=0
for(( i=1 ;i<=100;i=i+1))
do
s=s+1;
done
echo "the count is ==> $s "
你可以一句一句的复制到终端执行

发表于 : 2008-06-05 10:15
BigSnake.NET
第一行加

#! env /bin/bash -e

发表于 : 2008-06-05 10:25
laborer
把s=s+1替换为let s=s+1

发表于 : 2008-06-05 11:13
eexpress
(( x ))
要空格的