首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将Bash的过程替换与这里的文档结合起来?

如何将Bash的过程替换与这里的文档结合起来?
EN

Unix & Linux用户
提问于 2014-06-17 00:49:54
回答 2查看 5.6K关注 0票数 18

在BashVersion4.2.47(1)-release中,当我尝试对来自这里的文本的格式化文本进行链接时,如下所示:

代码语言:javascript
复制
cat <(fmt --width=10 <<FOOBAR
(I want the surrounding parentheses to be part of the HERE-document)
(Even the preceding unbalanced parenthesis should be part of it.
FOOBAR
) # I want this paranthesis to end the process substitution.

我得到以下错误:

代码语言:javascript
复制
bash: bad substitution: no closing `)' in <(fmt --width=10 <<FOOBAR
(I want the surrounding parentheses to be part of the HERE-document)
(Even the preceding unbalanced parenthesis should be part of it.
FOOBAR
)

另外,我不想引用这里的文档,即写<'FOOBAR',因为我仍然希望在其中替换变量。

EN

回答 2

Unix & Linux用户

发布于 2015-10-31 12:02:34

这是一个老问题,当您意识到这是一个人为的例子(因此正确的解决方案是使用cat |,或者在本例中实际上根本不使用cat )时,我将只发布我对一般情况的答案。我会把它放在一个函数中,然后用它来解决它。

代码语言:javascript
复制
fmt-func() {
    fmt --width=10 <<FOOBAR
(I want the surrounding parentheses to be part of the HERE-document)
(Even the preceding unbalanced parenthesis should be part of it.
FOOBAR
}

然后用它

代码语言:javascript
复制
cat <(fmt-func)
票数 8
EN

Unix & Linux用户

发布于 2014-06-17 00:55:48

这只是一个解决办法。将fmt输送到cat,而不是使用进程替换

代码语言:javascript
复制
fmt --width=10 <<FOOBAR | cat 
(I want the surrounding parentheses to be part of the HERE-document)
(Even the preceding unbalanced parenthesis should be part of it.
FOOBAR
票数 3
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/137506

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档