Confirm action loop

Published: Monday, Jul 17, 2017 Last modified: Monday, Dec 9, 2024

Here is such an example:

#!/bin/bash
confirm() { local ans IFS=; while read -rp "$1" -n1 ans; do printf '\n'; case $ans in [Yy]) return 0;; [Nn]) return 1;; esac; done; };
aws s3 ls | grep serverless | while read -r _ _ BUCKET
do
		if confirm "Execute $BUCKET" < /dev/tty
		then
				echo aws s3 rb --force s3://$BUCKET
		fi
done