How to pipe input to a Bash while loop and preserve variables after loop ends
问题 Bash allows to use: cat <(echo \"$FILECONTENT\") Bash also allow to use: while read i; do echo $i; done </etc/passwd to combine previous two this can be used: echo $FILECONTENT | while read i; do echo $i; done The problem with last one is that it creates sub-shell and after the while loop ends variable i cannot be accessed any more. My question is: How to achieve something like this: while read i; do echo $i; done <(echo \"$FILECONTENT\") or in other words: How can I be sure that i survives