码迷,mamicode.com
首页 > 系统相关 > 详细

linux shell 报错 Syntax error: Bad for loop variable

时间:2015-10-14 12:10:32      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:

在linux下写了一个简单的shell,循环10次.

test.sh

#!/bin/bash                        
##                                 
##循环10次                         
##                                 
for ((i=0; i<10; i++));            
                                   
do                                 
                                   
    echo Good Morning ,this is  $i  shell program.                                                                        
                                   
done

执行:sh test.sh 报下面的错误.

Syntax error: Bad for loop variable

在网上搜索了一下.

因为Ubuntu为了加快开机速度,用dash代替了传统的bash,所以我们这样执行就没问题.

bash test.sh

 

那如果我们只想用sh test.sh 这样的方式执行,怎么办呢?

修改一下代码.

for i in `seq 10`                  
do                                 
                                   
    echo Good Morning ,this is  $i  shell program.
                                   
done

这个时候,你再执行 sh test.sh,就不会报错误啦.

 

linux shell 报错 Syntax error: Bad for loop variable

标签:

原文地址:http://www.cnblogs.com/wangkongming/p/4876693.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!