【问题标题】:How to fix Cygwin error on angle brackets < > in a shell script?如何修复 shell 脚本中尖括号 < > 上的 Cygwin 错误?
【发布时间】:2019-03-27 06:14:19
【问题描述】:

我正在尝试让一个 shell 脚本在 Cygwin 中运行,并且在我在下面发布的缩减部分中它崩溃并显示如下错误:

new.sh:第 8 行:意外标记 `newline' 附近的语法错误

#!/bin/sh
set -eu

usage(){
    echo "$(cat <<"EOF")"
      sh new.sh <--repo REPO>+

    --repo | -r <REPO_URL>
      url of a repository to analyze
      REQUIRES --repo OR --repo-file

    --save-credentials | -s
      save credentials (in plain text) after running

    --help | -h
      shows this message

    EOF
}

没有导致此错误消息的回车。这似乎是尖括号&lt;&gt; 的结果。删除它们后,它会落在() 括号上。

这是代码问题还是 Cygwin 问题?有人可以提出解决办法吗?

【问题讨论】:

    标签: shell cygwin newline


    【解决方案1】:

    为什么是echo "$(cat &lt;&lt;"EOF")"?简化:cat &lt;&lt;'EOF'

    另外,终止的 EOF 不能有前面的空格,除非你使用 &lt;&lt;- 并且有严格的制表符来缩进。 http://www.gnu.org/software/bash/manual/bashref.html#Here-Documents

    【讨论】:

    • 谢谢,工作。我对 shell 语言了解不多,实际上并没有编写这个脚本,我只是被赋予了让它在 Windows 中的 Cygwin 上运行的工作。显然它像在 Linux 中一样工作正常。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-05
    • 1970-01-01
    • 2012-06-12
    • 1970-01-01
    • 2017-07-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多