bash-guide
bash-guide copied to clipboard
Improve the 2.4 Loops section.
I see two issues with your for loops section.
- Typo; In your 1st example. You use "end" to end the for loop, that is wrong it should be "done".
- It would be better to show some working examples
Instead of this:
for name [in list]
do
statements that can use $name
done
How about doing it this way:
for name in one two
do echo $name
done
Example output:
one
two
Anther for loop example:
more list.txt
one
two
for name in $(more list.txt)
do echo $name
done
Example output:
one
two
Currently a user of the can't just cut and past the code into there terminal to run. This way they can do that to test and learn how it works.
Also maybe add a read line section to the while loop section. Example:
more list.txt | while read line
do
echo "$line"
done
This kind of loop is good for varibles with spaces in.
I can do a pull request if you want and do it for you, just let me know.