如何使一个bash查找同一进程中运行? [英] How to make a bash find run in same process?

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

问题描述

code首先

echo $$ - $BASHPID

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

问题出在的code,而在一个子进程中运行。我怎样才能使这个运行在同一个进程?

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

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