Implementing a yes/no [y/n] confirmation prompt in Bash command line. Make the program exit when no or n is selected.
Hereโs an example.
read -p "Are you sure? " -n 1 -r
echo # (optional) move to a new line
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1
fi
echo "Yes"