如何让 bash find 在同一进程中运行? [英] How to make a bash find run in same process?

查看:14
本文介绍了如何让 bash find 在同一进程中运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码优先

echo $$ - $BASHPID

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

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

The problem is the code in while is running in a sub process. How can I make this run in the same process?

推荐答案

只需使用进程替换:

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 find 在同一进程中运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆