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

sh/bash/dash/ksh/zsh等Shell脚本
回复
头像
yangxiao
帖子: 48
注册时间: 2008-04-30 0:04
联系:

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

#1

帖子 yangxiao » 2008-06-04 21:17

刚学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
头像
solcomo
帖子: 2838
注册时间: 2007-04-25 13:12

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

#2

帖子 solcomo » 2008-06-04 21:36

yangxiao 写了:declare -i s=0
for(( i=1 ;i<=100;i=i+1))
do
s=s+1;
done
echo "the count is ==> $s "
你可以一句一句的复制到终端执行
♜♞♝♛♚♝♞♜
♟♟♟♟♟♟♟♟
♙♙♙♙♙♙♙♙
♖♘♗♕♔♗♘♖

☠☯⚔⚓☣☦☃☕
☹☻☪☭☬⚖⚛⚜
ℜℳℬ™ ℋℯℓ℘ ℳℭ
sƂɐʍ рǀɹoʍ əɥʇ oS
头像
BigSnake.NET
帖子: 12522
注册时间: 2006-07-02 11:16
来自: 廣州
联系:

#3

帖子 BigSnake.NET » 2008-06-05 10:15

第一行加

#! env /bin/bash -e
^_^ ~~~
要理解递归,首先要理解递归。

地球人都知道,理论上,理论跟实际是没有差别的,但实际上,理论跟实际的差别是相当大滴。
头像
laborer
帖子: 1016
注册时间: 2005-10-25 11:15
联系:

#4

帖子 laborer » 2008-06-05 10:25

把s=s+1替换为let s=s+1
hreiser@oakland:~$ killall -9 wife
police@oakland:~$ sudo find / -user hreiser
court@oakland:~$ sudo mv /home/hreiser /jail/
court@oakland:~$ sudo usermod -d /jail/hreiser -s "/usr/sbin/chroot /jail/" hreiser
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

#5

帖子 eexpress » 2008-06-05 11:13

(( x ))
要空格的
● 鸣学
回复