end of day 5 week 1
This commit is contained in:
31
week 1/day 5/exo3.sh
Executable file
31
week 1/day 5/exo3.sh
Executable file
@@ -0,0 +1,31 @@
|
||||
#!/bin/bash
|
||||
|
||||
read -p "Please enter your username: " username
|
||||
|
||||
if [[ -z "$username" ]]; then
|
||||
echo "You must enter a username"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
badChar=false
|
||||
|
||||
for ((i=0; i<${#username}; i++)); do
|
||||
char="${username:i:1}"
|
||||
if ! [[ "$char" =~ [A-Za-z] ]]; then
|
||||
badChar=true
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
firstChar="${username:0:1}"
|
||||
validFirstLetter=false
|
||||
|
||||
if [[ "$firstChar" =~ [A-Za-z] ]]; then
|
||||
validFirstLetter=true
|
||||
fi
|
||||
|
||||
if ! $badChar && (( ${#username} <= 20 )) && $validFirstLetter; then
|
||||
echo "The username $username is valid"
|
||||
else
|
||||
echo "The username is not valid"
|
||||
fi
|
||||
Reference in New Issue
Block a user