mirror of
https://github.com/Fechin/reference.git
synced 2026-11-21 05:24:10 +03:00
Update bash.md
Using original
```
cat file.txt | while read line; do
echo $line
done
```
is problematic, because changing variables inside the loop are lost outside. Example:
```
count=0
cat file.txt | while read line; do
count=$(( count+1 ))
echo $count":"$line
done
echo "total:"$count
```
outputs to
```
total:0
```
This commit is contained in:
1 parent
04f0dd3794
commit
19b09f6500
1 file changed
+2
-2
@@ -597,9 +597,9 @@ done
|
||||
### Reading lines
|
||||
|
||||
```bash
|
||||
cat file.txt | while read line; do
|
||||
while read line; do
|
||||
echo $line
|
||||
done
|
||||
done < file.txt
|
||||
```
|
||||
|
||||
## Bash Functions
|
||||
|
||||
Reference in new issue
Block a user