相关疑难解决方法(0)

How to detect an error using process substitution

This question is similar to the following link, but focused on using the command line (bash shell).

Using a simple example, when doing the following command:

$ cat <(date); echo $?
Fri Jul  7 21:04:38 UTC 2017
0
Run Code Online (Sandbox Code Playgroud)

The exit value is 0 as expected.

In the following command there is an error introduced on purpose, but the return value is still 0:

$ cat <(datE); echo $?
bash: datE: command not found...
Similar command is: 'date'
0
Run Code Online (Sandbox Code Playgroud)

Is …

bash pipe process-substitution exit-status

8
推荐指数
2
解决办法
2249
查看次数

在我可以等待 coproc 之前,Bash 取消了 *_PID 变量的设置

我正在尝试使用进程将异步进程的输出通过管道传输到其他 shell 命令,然后检查异步进程的退出状态:

coproc LS { ls dir; }
while IFS= read i; do echo "$i"; done <&"$LS" # Do something with the output.
wait "$LS_PID"; echo $? # Check exit status.
Run Code Online (Sandbox Code Playgroud)

问题是上面的代码不起作用,至少在 Bash 中不起作用4.3.46(1)-release。在之后while的语句已经执行,bash将取消设置$LS_PID(可能是因为它注意到,这一进程已经终止)。调用wait进程仍然有效,例如:

coproc LS { ls dir; }
P=$LS_PID
while IFS= read i; do echo "$i"; done <&"$LS" # Do something with the output.
wait "$P"; echo $? # Check exit status.
Run Code Online (Sandbox Code Playgroud)

这将打印02取决于目录是否存在。因此,我必须将 …

bash process

5
推荐指数
1
解决办法
629
查看次数

标签 统计

bash ×2

exit-status ×1

pipe ×1

process ×1

process-substitution ×1