Linux Cywgin未正确运行脚本

Linux Cywgin未正确运行脚本,linux,bash,cygwin,Linux,Bash,Cygwin,您好,我正在尝试在cygwin中运行此脚本,但它无法正常工作。不过,在linux下运行时,它运行良好 错误: $ ./script2.txt >> count.txt ./script2.txt: line 3: syntax error near unexpected token `|' '/script2.txt: line 3: ` | grep PlayerCount \ 原文: #!/usr/bin/bash wget --output-document=- htt

您好,我正在尝试在cygwin中运行此脚本,但它无法正常工作。不过,在linux下运行时,它运行良好

错误:

$ ./script2.txt >> count.txt
./script2.txt: line 3: syntax error near unexpected token `|'
'/script2.txt: line 3: `    | grep PlayerCount \
原文:

#!/usr/bin/bash
wget --output-document=- http://runescape.com/title.ws 2>/dev/null \
    | grep PlayerCount \
    | head -1l \
    | sed 's/^[^>]*>//' \
    | sed "s/currently.*$/$(date '+%r %b %d %Y')/"
某人要求的:

$ od -a script2.txt
0000000   #   !   /   u   s   r   /   b   i   n   /   b   a   s   h  cr
0000020  nl   w   g   e   t  sp   -   -   o   u   t   p   u   t   -   d
0000040   o   c   u   m   e   n   t   =   -  sp   h   t   t   p   :   /
0000060   /   r   u   n   e   s   c   a   p   e   .   c   o   m   /   t
0000100   i   t   l   e   .   w   s  sp   2   >   /   d   e   v   /   n
0000120   u   l   l  sp   \  cr  nl  sp  sp  sp  sp   |  sp   g   r   e
0000140   p  sp   P   l   a   y   e   r   C   o   u   n   t  sp   \  cr
0000160  nl  sp  sp  sp  sp   |  sp   h   e   a   d  sp   -   1   l  sp
0000200   \  cr  nl  sp  sp  sp  sp   |  sp   s   e   d  sp   '   s   /
0000220   ^   [   ^   >   ]   *   >   /   /   '  sp   \  cr  nl  sp  sp
0000240  sp  sp   |  sp   s   e   d  sp   "   s   /   c   u   r   r   e
0000260   n   t   l   y   .   *   $   /   $   (   d   a   t   e  sp   '
0000300   +   %   r  sp   %   b  sp   %   d  sp   %   Y   '   )   /   "
0000320

您有DOS样式的行尾。我怀疑这就是问题的原因:

0000120 u l l sp\cr nl sp | sp g r e 那里应该只有
nl
。但是,在Linux之间传输文件的过程中,正在对您进行行尾转换


请尝试
flip
conv
d2u
dos2unix
等进行修复。

您需要的文件不具有windows样式的行尾

dos2unix script2.txt script2.txt

或者,使用编辑器设置行尾。例如,在vim中,您将使用
:set ff=unix

请发布
od-a script2.txt的结果,您的意思是错误?还是从实际工作的脚本中?编辑:正在处理它。
dos2unix script2.txt script2.txt