- 1. Arithmetic
- 2. filesystem-related conditions
- 3. or for reading input
- 4. Elegant endless loop
- 5. Modify variable inside a while loop
1. Arithmetic
while (( COUNT < MAX ))
do
some stuff
let COUNT++
done
while [ -z "$LOCKFILE" ]
do
some things
done
You can pass standard output to these lines:
while read lineoftext
do
process $lineoftext
done
Uff really elegant
while : ## Elegant Endless loop
do
echo "Do something"
done
#/bin/bash
# Inside while loop will not be modified variable movie
echo "First time"
movie=""
echo ${movie}
cat movies.txt | cut -d "." -f 2 | while read movie_name; do
if echo "${movie_name}" | grep "Kid"; then
movie="${movie_name}"
fi
done
echo "${movie}"
echo "Second time"
while IFS= read -r movie_name; do
if echo "${movie_name}" | grep "Kid"; then
movie="${movie_name}"
fi
done < movies.txt