34 lines
651 B
Bash
Executable File
34 lines
651 B
Bash
Executable File
#!/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
|
|
|