2

Code first

echo $$ - $BASHPID

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

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

fedorqui
  • 275,237
  • 103
  • 548
  • 598
wener
  • 7,191
  • 6
  • 54
  • 78

1 Answers1

9

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.

fedorqui
  • 275,237
  • 103
  • 548
  • 598