bash - 如何使 bash 查找在同一进程中运行?

标签 bash find

代码优先

echo $$ - $BASHPID

find . | while read -r file; do
    echo $$ - $BASHPID: ${file}
done

问题是 while 中的代码在子进程中运行。我怎样才能让它在同一个进程中运行?

最佳答案

只需使用 process substitution :

echo "$$ - $BASHPID"

while read -r file; do
    echo "$$ - $BASHPID: ${file}" #better to quote!
done < <(find .)
# -----^^^^^^^^^

来自给定的链接:

Process substitution is a form of redirection where the input or output of a process (some sequence of commands) appear as a temporary file.

关于bash - 如何使 bash 查找在同一进程中运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30870059/

相关文章:

linux - 命令脚本将文件识别为目录

bash - 在 bash 中读取带有 "read"的一行,但没有 "while"

Javascript/jQuery 查找和替换

python - JavaScript 的 Array.prototype.find 的 python 等价物是什么?

bash - 我的美元?命令成功代码失败,为什么?

bash - 从 Vim 执行 Bash 中的当前行

python - 在 python 中使用重定向运行 bash 命令

linux - 是否可以在 Linux 中可靠地嵌套 find -exec 命令?

Windows 相当于 Unix "find"命令?

javascript - 按类名查找 div 并将其替换为基于 onclick - jquery 的 div