From 19b09f65003993a6f26d0b44add41e2af9f10426 Mon Sep 17 00:00:00 2001 From: oheil Date: Sat, 12 Jul 2025 12:07:57 +0200 Subject: [PATCH] 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 ``` --- source/_posts/bash.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/_posts/bash.md b/source/_posts/bash.md index 3f53f59..6b5a12b 100644 --- a/source/_posts/bash.md +++ b/source/_posts/bash.md @@ -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