mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-08-11 17:24:29 +02:00
Merge pull request #716 from LumenTeun/master
Fixed some typos and added more for loops.
This commit is contained in:
@@ -134,14 +134,28 @@ case "$VARIABLE" in
|
|||||||
esac
|
esac
|
||||||
|
|
||||||
# for loops iterate for as many arguments given:
|
# for loops iterate for as many arguments given:
|
||||||
# The contents of var $VARIABLE is printed three times.
|
# The contents of $VARIABLE is printed three times.
|
||||||
for VARIABLE in {1..3}
|
for VARIABLE in {1..3}
|
||||||
do
|
do
|
||||||
echo "$VARIABLE"
|
echo "$VARIABLE"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# They can also be used to act on files..
|
||||||
|
# This will run the command 'cat' on file1 and file2
|
||||||
|
for VARIABLE in file1 file2
|
||||||
|
do
|
||||||
|
cat "$VARIABLE"
|
||||||
|
done
|
||||||
|
|
||||||
|
# ..or the output from a command
|
||||||
|
# This will cat the output from ls.
|
||||||
|
for OUTPUT in $(ls)
|
||||||
|
do
|
||||||
|
cat "$OUTPUT"
|
||||||
|
done
|
||||||
|
|
||||||
# while loop:
|
# while loop:
|
||||||
while [true]
|
while [ true ]
|
||||||
do
|
do
|
||||||
echo "loop body here..."
|
echo "loop body here..."
|
||||||
break
|
break
|
||||||
|
Reference in New Issue
Block a user