超简单脚本,无法运行?

sh/bash/dash/ksh/zsh等Shell脚本
回复
fnan
帖子: 919
注册时间: 2009-07-01 22:04

超简单脚本,无法运行?

#1

帖子 fnan » 2011-03-01 6:15

kose5@kose5-Aspire-4552:~$ for((i=0;i<=5;i++));do
> echo $i;
> done
0
1
2
3
4
5

kose5@kose5-Aspire-4552:~$ cat rand.sh
#!/bin/bash
for((i=0;i<=5;i++));do
echo $i;
done

kose5@kose5-Aspire-4552:~$ sh rand.sh
rand.sh: 2: Syntax error: Bad for loop variable
bash不如perl精妙,学不到lisp的皮毛,远不够c++强悍,不过可以用。
头像
ebok
帖子: 852
注册时间: 2008-02-15 0:09

Re: 超简单脚本,无法运行?

#2

帖子 ebok » 2011-03-01 10:15

既然是#!/bin/bash
为何要用sh去执行脚本,用sh执行脚本会导致很多bash的新特性无法使用.
Somebody think they are full of niubility, so they play a zhuangbility, but only reflect their shability.
fnan
帖子: 919
注册时间: 2009-07-01 22:04

Re: 超简单脚本,无法运行?

#3

帖子 fnan » 2011-03-01 20:19

用#!/bin/sh 也不行。
./rand.sh 也不行。
bash不如perl精妙,学不到lisp的皮毛,远不够c++强悍,不过可以用。
头像
ebok
帖子: 852
注册时间: 2008-02-15 0:09

Re: 超简单脚本,无法运行?

#4

帖子 ebok » 2011-03-01 20:33

用#!/bin/sh与 sh scriptname 一样

要想用 ./scriptname 请先加x 权限

想学shell请看ABS ==> <<advanced bash shell scripting>>
Somebody think they are full of niubility, so they play a zhuangbility, but only reflect their shability.
fnan
帖子: 919
注册时间: 2009-07-01 22:04

Re: 超简单脚本,无法运行?

#5

帖子 fnan » 2011-03-01 20:34

加x权限也不行。
bash不如perl精妙,学不到lisp的皮毛,远不够c++强悍,不过可以用。
fnan
帖子: 919
注册时间: 2009-07-01 22:04

Re: 超简单脚本,无法运行?

#6

帖子 fnan » 2011-03-01 20:50

活见鬼了,昨天x加来加去都不行,今天可以了,可能是昨天rp不好, 无语。
还是要谢谢ebox。
bash不如perl精妙,学不到lisp的皮毛,远不够c++强悍,不过可以用。
回复