小编Hug*_*den的帖子

使用bash进程替换拒绝文件描述符权限?

我有一个bash脚本,我想在标准输出中与用户通信,但也通过文件描述符将命令发送到子进程 - 如下所示:

# ...
# ...

echo "Hello user, behold a cleared gnuplot window"

# pass the string "clear" to gnuplot via file descriptor 3
echo "clear" >&3  
Run Code Online (Sandbox Code Playgroud)

所以我认为我可以通过首先启动子进程来"设置它":

#!/bin/bash

# Initiate(?) file descriptor 3, and let it direct to a newly 
# started gnuplot process:
exec >3 >( gnuplot )
Run Code Online (Sandbox Code Playgroud)

但这会产生错误:

/dev/fd/63: Permission denied
Run Code Online (Sandbox Code Playgroud)

这是预期的吗?

我不明白发生了什么.(我做错了什么?可能是我的系统有一些特殊的安全设置,不允许我正在尝试做什么?(运行Ubuntu Linux 12.10.))

"解决方法" - 以下似乎与我正在尝试的内容相同,并且可以正常工作:

#!/bin/bash

# open fd 3 and direct to where fd 1 directs to, i.e. std-out 
exec 3>&1 …
Run Code Online (Sandbox Code Playgroud)

bash file-descriptor permission-denied process-substitution

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