Skip to content

Improve the 2.4 Loops section. #104

@2bitninja

Description

@2bitninja

I see two issues with your for loops section.

  1. Typo; In your 1st example. You use "end" to end the for loop, that is wrong it should be "done".
  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions