Skip to main content

For loops

Compute md5sum for every item in a directory

for i in "$(ls)"; do md5sum "${i}"; done | sort

Print 1 through 10

for COUNT in $(seq 1 10); do
  echo $COUNT
  sleep 1
done

Read data into an array and loop over it

mapfile -t buckets < <(aws s3 ls | grep tf | awk '{print $3}' | tr " " "\n")
for b in "${buckets[@]}"; do echo "TF Bucket: $b"; done

Old method that does not spark joy for linters

buckets=($(aws s3 ls |grep tf | awk '{print $3}' | tr " " "\n"))
for b in "${buckets[@]}"; do echo "TF Bucket: $b"; done