From cabeaafab5b08d91ac394162edc2cc08d6a4e23a Mon Sep 17 00:00:00 2001 From: Douglas Barone Date: Wed, 1 Mar 2023 12:53:47 -0400 Subject: [PATCH] Append char if only numeric --- pdc-add-user-professor.sh | 6 ++++++ pdc-add-user-servidor.sh | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/pdc-add-user-professor.sh b/pdc-add-user-professor.sh index 96577db..c00f0bd 100755 --- a/pdc-add-user-professor.sh +++ b/pdc-add-user-professor.sh @@ -25,6 +25,12 @@ if [[ $USERNAME =~ " " ]]; then exit 1 fi +# Check if $USERNAME starts with a number +if [[ $USERNAME =~ ^[0-9] ]]; then + echo "Username cannot start with a number. Appending 'u' to the beginning of the username..." + USERNAME="u$USERNAME" +fi + NAME=$(echo $NAME | tr "[A-Z]" "[a-z]" | sed -e "s/\b\(.\)/\u\1/g") # Check if $USERNAME is already in use diff --git a/pdc-add-user-servidor.sh b/pdc-add-user-servidor.sh index f344f76..61bd13e 100755 --- a/pdc-add-user-servidor.sh +++ b/pdc-add-user-servidor.sh @@ -25,6 +25,12 @@ if [[ $USERNAME =~ " " ]]; then exit 1 fi +# Check if $USERNAME starts with a number +if [[ $USERNAME =~ ^[0-9] ]]; then + echo "Username cannot start with a number. Appending 'u' to the beginning of the username..." + USERNAME="u$USERNAME" +fi + NAME=$(echo $NAME | tr "[A-Z]" "[a-z]" | sed -e "s/\b\(.\)/\u\1/g") # Check if $USERNAME is already in use