windows Cygwin bash 文件的帮助

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2818287/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 14:26:55  来源:igfitidea点击:

Help with Cygwin bash file

windowscygwinbash

提问by Mestika

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:

我有一个 bash 文件,我试图在 Windows 7 平台上的 Cygwin 中运行它,但是这样做时我给了我一些奇怪的错误。bash 文件适用于我的 Linux 系统。bach 文件如下所示:

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:

但是我的 for 循环出错了。更准确的是它写道:

./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.

我不明白,因为我确信我的 Linux 上有一个工作 bash 文件。我什至试图从 Linux-bash 站点找到一个 for-loop 示例并运行它,但出现相同的错误。

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.

我是 Cygwin 的新手,不知道它是否有一些小怪癖或其他一些我必须注意的事情,我试图查看他们主页上的文档和常见问题解答。

Sincere

真诚

Mestika

梅斯蒂卡

回答by Paul R

You seem to be missing a doand a shebang line:

你似乎缺少一个do和一个shebang行:

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

回答by Mestika

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

是的,我发现我的文本编辑器(记事本++)被设置为 DOS/Windows 格式,我只是将其更改为 UNIX 并且它起作用了:-)

回答by Oleg Razgulyaev

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

你应该用 do .. done
'do'正确标记循环块

回答by Oleg Razgulyaev

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

也许 bash 的 Cygwin 版本比 Linux 版本老得多?这适用于 MSYS bash:

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

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

请注意,我已将do关键字添加到循环中。您还可以尝试将循环编写为:

for r in 0 1 2 3 4 5 6 7 8 9
do
    echo $r
done

回答by Joe

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

以下脚本将在端口 0-65000 上执行 ssh,并将每次执行的所有日志输出到名为 log.txt 的文件中

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

将“host”替换ssh -tt -p $r host为您希望“ssh”到的主机地址。

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

-tt 命令强制 tty 分配并停止伪终端的分配。(强制壳)

#!/bin/bash
for (( r=0; r<65000; r++ ))
do
    ssh -tt -p $r host -E log.txt < log.txt
done
wait