linux shell脚本中for循环的语法 [英] syntax of for loop in linux shell scripting

查看:32
本文介绍了linux shell脚本中for循环的语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在实现 for 循环时遇到问题.执行脚本时出现此错误

I have a problem implementing a for loop. I get this error when I execute my script

test1.sh: 2: 语法错误:循环变量错误

test1.sh: 2: Syntax error: Bad for loop variable

我不明白这个错误.

这是我的剧本

#!/bin/bash
for (( c=1; c<=5; c++ ))
do
echo "Welcome $c times..."
done

谁能告诉我 ubuntu 中 sh(在 ubuntu 中它链接到 dash shell)shell 中 for 循环的语法?

can any one tell me syntax for for loop in sh(in ubuntu it links to dash shell) shell in ubuntu?

推荐答案

您可能使用 sh 而不是 bash 运行它.尝试 bash test1.sh,或者 ./test1.sh 如果它是可执行的,但不是 sh test1.sh.

You probably run it with sh, not bash. Try bash test1.sh, or ./test1.sh if it's executable, but not sh test1.sh.

这篇关于linux shell脚本中for循环的语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆