微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

linux-Cywgin无法正确运行脚本

您好,我试图在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

解决方法:

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

dos2unix script2.txt script2.txt

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐