[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-bash] Why variables are not set in a while-read loop?
From: |
Peng Yu |
Subject: |
[Help-bash] Why variables are not set in a while-read loop? |
Date: |
Sat, 21 Mar 2015 16:39:01 -0500 |
Hi,
I thought the following two while loops are different in the sense
that the first one involves a subshell, but the second doesn't.
Consequently, I should see $file with some value printed after the
second loop but not the first loop.
However, neither of them print $file with some content. Can anybody
help me understand why? Thanks.
~$ cat main.sh
#!/usr/bin/env bash
find .. -type f -print0 | while IFS= read -r -d '' file
do
echo "$file"
done
echo xxx $file
while IFS= read -r -d '' file
do
echo "$file"
done < <(find .. -type f -print0)
echo xxx $file
--
Regards,
Peng
- [Help-bash] Why variables are not set in a while-read loop?,
Peng Yu <=