end of day 5 week 1
This commit is contained in:
33
week 1/day 5/exo4.sh
Executable file
33
week 1/day 5/exo4.sh
Executable file
@@ -0,0 +1,33 @@
|
||||
#!/bin/bash
|
||||
|
||||
users=("admin" "root1" "John_Doe" "Alice" "Bob42")
|
||||
|
||||
badChar=false
|
||||
|
||||
for username in "${users[@]}"; do
|
||||
|
||||
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 $username is not valid"
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
Reference in New Issue
Block a user