问题标签 [process-substitution]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
0 回答
112 浏览

c - 从文件或文件描述符中读取

输出:

即使文件是通过bash进程替换获得的文件描述符,有没有办法让它工作?

0 投票
1 回答
465 浏览

python - Python heredoc 如何用作 Bash 进程替换的输入?

我有一个 Python 脚本,它定义了 tmux 的配​​置,然后使用此配置启动 tmux。配置在 Python 中存储为 heredoc,我想在为 tmux 执行 Bash 启动命令时在 Bash 进程替换中使用它。

所以,我想做这样的事情:

我应该改变什么才能让它工作?

0 投票
0 回答
90 浏览

bash - 在 Bash 中,如何使用进程替换为 Pandoc 创建模板?

我正在尝试修改默认的 Pandoc LaTeX 模板(有关表格的小设置),并且我正在尝试执行此操作,并且 Pandoc 在一个命令中运行。当我尝试执行命令时出现错误pandoc: Could not find data file /dev/fd/63.latex,我不知道如何解决它。命令如下:

pandoc --template <(pandoc --print-default-template=latex | sed 's/longtable,//') -f markdown -t latex report.md -o report.pdf

我应该如何做这个过程替换?

0 投票
0 回答
172 浏览

bash - 与 Bash 中的 push `while` 循环相比,pull `while` 循环有哪些优点/缺点

有很多方法可以在 bash 的 while 循环中使用数据。

其中之一是

另一个是

问题 1:我什么时候应该更喜欢其中一个。

问题 2:如果我不是从进程中读取some_proc而是redirection直接在文件上使用,那么该文件何时打开和关闭。

0 投票
2 回答
62 浏览

bash - 部分从 bash 进程替换中消耗,将其挂起并在另一个函数中从中读取其余部分

有没有办法只消耗来自 Bash 进程替换的部分数据,暂停进程替换并在另一个函数中从中读取剩余数据。我想这样做而不将结果存储到中间文件中。我尝试了显而易见的方法:将进程替换存储在一个变量中并从中读取,但这不起作用。

我有一个生成已经包含在进程替换中的数据的进程。可以说是<(first_command)。我想部分使用它function-1,然后将其余数据(由 first_command 生成)传递给function-2.

0 投票
2 回答
4045 浏览

linux - Bash 脚本进程替换语法错误:“(”意外

我想运行这个脚本:

我将其运行为:

我得到“ Syntax error: "(" unexpected”。我发现了一些类似的情况,但仍然无法解决这个问题。我是 shell scripting 的初学者,但据我了解:

  1. 我使用的 shebang 是正确的,并且选择了 bash shell,所以进程替换语法应该可以工作
  2. 我从命令行尝试相同的方法,它可以工作。我检查了一下echo $0,它给了我 " bash" ,那么在命令行中运行命令和调用相同 shell 的脚本有什么区别?

也许这很简单,但我找不到解释或解决方案。

0 投票
1 回答
1776 浏览

bash - 为什么 source 命令不适用于 bash 3.2 中的进程替换?

我有以下 shell 脚本:

但是它在 GNU bash 3.2 和 4.3 中的工作方式不同,如下所示:

为什么这只适用于一个版本?这是一个错误还是添加的功能?

似乎流程替换工作正常,但是在获取文件时存在问题。

如果这是预期的行为,我应该使用什么其他语法来代替source标准输入中的内容以在不同的 bash 版本之间兼容?

0 投票
1 回答
792 浏览

shell - Is skipping/ignoring NUL bytes on process substitution standardized?

Executive Summary

Is it standard behavior that shells skip over NUL bytes when doing process substitution?

For example, executing

will yield abc. The NUL value is skipped, even though the hexdump of the printf output shows it's clearly being output.

My first thought was "word splitting". However, when using an actual process substitution

the results are similar and = does not perform word splitting.

Long Story

While searching for the proper answer for this question, I realized that at least three of the shell implementation (ash, zsh, and bash) I am reasonably familiar with will ignore a NUL character when reading the value from process substitution into a variable.

The exact point in the pipeline when this happens seems to be different, but the result is consistently that a NUL byte gets dropped as if it was never there in the first place.

I have checked with some of the implementations, and well, this seems to be normal behavior.

ash will skip over '\0' on input, but it is not clear from the code if this is pure coincidence or intended behavior:

The bash source code contains an explicit, albeit #ifdef'd warning telling us that it skipped a NUL value on process substitution:

I'm not so sure about zsh's behaviour. It recognizes '\0'as a meta character (as defined by the internal imeta() function) and prepends a special Meta surrogate character and sets bit #5 on the input character, essentially unmetaing it, which makes also makes '\0' into a space ' ')

This seems to get stripped later because there is no evidence that value in the above printf command contains a meta character. Take this with a large helping of salt, since I'm not to familiar with zsh's internals. Also note the side effect free statements.

Note that zsh also allows you to include NUL (meta-escaped) in IFS (making it possible to e.g. word-split find -print0 without xargs -0). Thus printf '\0abc' | read value and value=$(printf '\0abc') should yield different results depending on the value of IFS (read does field splitting).

0 投票
1 回答
515 浏览

bash - 进程替换在 bash 中工作,但不是 zsh

我正在尝试使用进程替换来提供一个 while 循环。

这在 bash 中可以正常工作,但在 zsh 中不行。我收到此错误:

我正在使用 zsh 4.3.10。

我如何让它在 zsh 中工作?

更新:已修改问题以共享完整代码

0 投票
1 回答
1200 浏览

bash - Bash 重定向:命名管道和 EOF

采取以下代码:

为什么方法 #3 挂起,而其他方法则没有?有没有办法让方法#3 不挂起?

理由:我希望使用准未命名管道来连接几个异步运行的子进程,为此我需要在文件描述符指向它之后删除管道: