Why not transform the response to all caps first, and then compare with Y or YES, for example, do:
if [[ ${response^^} =~ ^(Y|YES)$ ]]; then ... fi
This has the advantage that you do not need to think about possible upper / lower case combinations, they are all detected. In addition, instead of:
if [[ $? == 0 ]]; then ... fi
You can simply do:
if [[ $? ]]; then ... fi
For truth tests, the result [[ 0 ]] is true, while the result (( 0 )) is false.
Consider some simplifications for readability, such as
function db_backup { read -r -p "Dump the database? [Y/n]: " response if [[ ${response^^} =~ ^(Y|YES)$ ]] then if mysqldump -h $1 -u $2 -p$3 $4 > $4.sql then printf "Database %s dumped successfuly in %s.sql\n" ${db_name} ${db_name} return 0 else printf "Database backup %bfailed%b\n" ${red} ${reset} return 1 fi else return 1 fi }
source share