end of day 5 week 1

This commit is contained in:
2026-01-22 21:36:02 +01:00
parent 82b79336ea
commit 3e23329086
8 changed files with 529 additions and 0 deletions

33
week 1/day 5/exo4.sh Executable file
View 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