首页 > 系统服务 > 详细

linux shell 报错 Syntax error: Bad for loop variable

时间:2015-10-14 12:10:10      阅读:182      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!