views:

147

answers:

4

Hi,

I have a bash file, which I’m trying to run in Cygwin on a Windows 7 platform, but I gives me some odd errors when doing so. The bash file works on my Linux system. The bach file looks like this:

for ((r=0; r <10; r++))

    netcat localhost 4444 < myfile.file &

done

wait

but I’m getting an error for my for-loop. More precise it writes:

./tuning_test.bsh: line 1: syntax error near unexpected token `('

'/tuning_test.bsh: line 1: `?for ((r=0; r <10; r++))

I do not understand it because I was sure that I’ve a working bash file on my Linux. I even tried to find a for-loop example from a Linux-bash site and run it but with same error.

I’m brand new to Cygwin and doesn’t know if it has some small quirks or some other thing I have to be aware of and I’ve tried to look through the documentation and FAQ on their homepage.

Sincere

Mestika

A: 

you should properly mark loop block with do .. done
'do' missed

oraz
A: 

Perhaps the Cygwin version of bash is a lot older than the Linux one? This works for me with MSYS bash:

for ((r=0; r <10; r++))
do
    echo $r
done

Note that I've added the do keyword to the loop. You can also try writing the loop as:

for r in 0 1 2 3 4 5 6 7 8 9
do
    echo $r
done
anon
Or `for r in {0..9}`
Dennis Williamson
@Dennis Doesn't work for me.
anon
`for r in {0..9}; do echo $r; done` - standard Bash. (also works in zsh and ksh93, but I don't think it's specified in POSIX)
Dennis Williamson
@Dennis Not with the version of bash I'm using I'm afraid - it produces the output `{0..9}`.
anon
You must be using Bash 2.x or earlier. The range brace expansion was introduced in 3.0 around July 2004.
Dennis Williamson
@Dennis Yes, 2.04. As I still write almost all my scripts as if I were using the Bourne shell, this is not too much of an issue for me :-)
anon
+3  A: 

You seem to be missing a do and a shebang line:

#!/bin/bash
for (( r=0; r<10; r++ ))
do
    netcat localhost 4444 < myfile.file &
done
wait
Paul R
A: 

Hi,

yeah I found out that my texteditor (notepad++) was sat to DOS/Windows formatting, I just changed it to UNIX and it worked :-)

Mestika