小编qua*_*sar的帖子

POSIX shell 注释与续行

编辑以澄清我的问题:

POSIX 说:

如果 <newline> 跟在(不带引号的)<backslash> 后面,则 shell 会将其解释为行继续。在将输入拆分为标记之前,应删除 <backslash> 和 <newline>。

然而,dash或其他实现,首先对输入进行标记。结果,\<newline>不被识别而是# this is a comment \被丢弃。这种行为符合 POSIX 标准吗?POSIX 再次表示,在标记化之前应删除行延续

下面的过程真的不符合 POSIX 标准吗?

  1. 读取整个输入:"echo hello ... \<newline> ... bye"
  2. 搜索未引用的内容\<newline>并将其删除:"echo hello ... bye"
  3. 标记化:"echo"(discard ' ')"hello"(discard ' ')(discard "# ... bye")

在 Ubuntu 上使用 dash-0.5.10.2-6 sh (dash) 我们得到以下内容

$ cat /var/tmp/test.sh
echo hello # this is a comment \
echo bye

$ sh /var/tmp/test.sh
hello
bye …
Run Code Online (Sandbox Code Playgroud)

shell posix

5
推荐指数
2
解决办法
816
查看次数

标签 统计

posix ×1

shell ×1