Solved bob in Bash

This commit is contained in:
2023-04-28 20:30:04 +02:00
parent 56fc641009
commit 81521122ff
7 changed files with 1057 additions and 0 deletions

20
bash/bob/bob.sh Normal file
View File

@@ -0,0 +1,20 @@
#!/usr/bin/env bash
# matches any character that is not in the set of letters, digits, and question marks.
cleaned="${1//[^a-zA-Z0-9\?]}"
# all capitals and ending with ?
if [[ "$cleaned" =~ ^[A-Z]+\?$ ]] ; then
echo "Calm down, I know what I'm doing!"
# ending with ?
elif [[ "$cleaned" =~ ^.*[a-z0-9]*.*\?$ ]] ; then
echo 'Sure.'
# all capitals and not only digits
elif [[ "$cleaned" =~ ^[A-Z0-9]+$ ]] && ! [[ "$cleaned" =~ ^[0-9]+$ ]] ; then
echo 'Whoa, chill out!'
# if empty
elif [[ -z "$cleaned" ]] ; then
echo 'Fine. Be that way!'
else
echo 'Whatever.'
fi