How to make a bash find run in same process?

后端 未结 1 426
北恋
北恋 2020-12-04 03:18

Code first

echo $$ - $BASHPID

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

The problem is the code in while<

相关标签:
1条回答
  • 2020-12-04 03:54

    Just use process substitution:

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

    From the given link:

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

    0 讨论(0)
提交回复
热议问题