Skip to content

Update bash.md #699

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 17, 2025
Merged

Update bash.md #699

merged 1 commit into from
Jul 17, 2025

Conversation

oheil
Copy link
Contributor

@oheil oheil commented Jul 12, 2025

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

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
```
@Fechin Fechin merged commit dd7bc29 into Fechin:main Jul 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants