【发布时间】:2021-03-23 19:02:18
【问题描述】:
我的 gnu bash 脚本 GNU bash,版本 5.1.0(1)-release (x86_64-apple-darwin19.6.0) 当 macos 包含超过 512 个字符的heredoc 时,它们会挂起, 例如下面的 USAGE heredoc 有效,除非我再添加 1 个字符
cat <<'USAGE'
--all List all tasks, TASK_IDs will be ignored
--name NAME Only list tasks with specified NAME
--logs list log messages
--pending Only list tasks that have not been scheduled
--active same as --pending
--scheduled Only List tasks that have been scheduled, whether running or finished
--running Only List tasks that are currently executing / running
--finished Only List tasks that have been run, i.e., have finished
12345678901234567890
USAGE
注意:没有变量扩展、引号等。只有文字。
如果我将所有文本分成多个 heredocs,它们都可以工作......但如果我将它们组合起来以创建一个 >512 个字符的 heredoc,bash 挂起
我做错了什么?
【问题讨论】:
-
我无法在 5.1.0(1)-release (x86_64-apple-darwin19.6.0) 上重现此内容。这是我尝试过的:1. 将脚本复制到文件
foo,2. 在USAGE之前添加一行“foobar”,3. 运行bash foo。脚本按预期将数据写入标准输出 -
很有趣,感谢您的反馈,但是......它在我的系统上失败了。顺便说一句,我没有发布我的 macos 版本:19.6.0 Darwin Kernel Version 19.6.0:Thu Oct 29 22:56:45 PDT 2020; root:xnu-6153.141.2.2~1/RELEASE_X86_64 x86_64 也许这就是问题所在?
-
此外,这些年来我收到了许多带有“USAGE”消息的 shell 脚本,直到最近才注意到这个问题。
-
只是回显一个字符串是多么奇怪的结构。为什么不简单地使用
echo后跟一个包含在引号中的多行字符串?