For Loop
SH · Bash Scriptingfor var in list; do
commands
donefor host in web01 web02 web03; do
echo "Deploying to ${host}..."
scp app.tar.gz deploy@"${host}":/opt/releases/
done
# C-style:
for ((i=1; i<=5; i++)); do
echo "Attempt ${i}"
doneDeploying to web01...
Deploying to web02...
Deploying to web03...Note Never parse ls output in a for loop. Use globs instead: for f in *.log; do ... done. For iterating over lines in a file: while IFS= read -r line; do ... done < file.txt.