如何防止bash在进行多进程替换时返回相同的路径?

How to prevent bash from returning the same path when doing multiple process substitution?

我想使用进程替换将一些字符串作为文件传递:

arg() {
    if true; then
        echo <(echo file)
    else
        echo inline
    fi
}

config() {
    echo config content
}

echo -arg $(arg) -config <(config)

-arg 可以接受文件路径或内联值。所以我为它创建了一个函数。

但问题是这个脚本输出

-arg /dev/fd/63 -config /dev/fd/63

这是错误的,因为这两个标志接收到相同的内容。

是因为 arg 是 运行 在一个新的 shell 中吗?

我想知道如何告诉 bash 不要对多个进程替换使用相同的路径?

我正在使用 bash 4.4.12

问题是 <(..) 的返回值必须在同一命令中使用。文件描述符在命令上下文之外不再有效。

arg 函数中,文件描述符 63 打开以读取 echo file 命令的输出,但未被读取,之后不再有效。