I would like to store a variable ($random) from the loop statement - currently only the last statement from the loop is printed. Please note that I would like to use this variables outside of the loop.
#!/usr/bin/env bash
for backup in $(s3cmd ls s3://bucket/ | awk '{ print $2 }')
do
latest=$(s3cmd ls $backup | awk '{ print $2 }' | sed -n '$p')
random=$(s3cmd ls $latest | shuf | awk '{ print $4 }' | sed -n '1p')
s3cmd get $random $data_dir >/dev/null 2>&1
done
echo "$random