3

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

Emil Devantie Brockdorff
  • 4,724
  • 12
  • 59
  • 76

5 Answers5

5

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
  • 208,748
  • 37
  • 389
  • 560
2

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

Emil Devantie Brockdorff
  • 4,724
  • 12
  • 59
  • 76
1

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

Oleg Razgulyaev
  • 5,757
  • 4
  • 28
  • 28
1

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
  • `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 May 12 '10 at 14:17
  • @Dennis Not with the version of bash I'm using I'm afraid - it produces the output `{0..9}`. –  May 12 '10 at 14:57
  • You must be using Bash 2.x or earlier. The range brace expansion was introduced in 3.0 around July 2004. – Dennis Williamson May 13 '10 at 00:33
  • @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 :-) –  May 13 '10 at 07:34
0

The below script will execute ssh on ports 0-65000 and output all logs for each execution to a file called log.txt

Replace "host" in ssh -tt -p $r host with the host address you wish to "ssh" into.

The -tt command forces tty allocation and stops the allocation of a pseudo-terminal. (Forces a shell)

#!/bin/bash
for (( r=0; r<65000; r++ ))
do
    ssh -tt -p $r host -E log.txt < log.txt
done
wait
Joe
  • 1,316
  • 9
  • 17
  • While this code may solve the question, [including an explanation](//meta.stackexchange.com/q/114762) of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please [edit] your answer to add explanations and give an indication of what limitations and assumptions apply. – double-beep Apr 01 '19 at 07:34