Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
736 views
in Technique[技术] by (71.8m points)

bash - syntax of for loop in linux shell scripting

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

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

I don't understand this error.

This is my script

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...