read -r -p "Are you sure? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]]
then
do_something
else
do_something_else
fi
I saw this script on a stack overflow website I used the following script because I couldn't write one myself because it threw errors. I know this script will wait for user input such as y/n but I would like detailed explanation about how this script works like what does =~
do and what does ^([yY][eE][sS]|[yY])+$ ]]
do.