Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- chck_rgx () { # Checks that the given name for a user/group fulfills the regex. The function's parameters are
- # * $1: kind of name to check: username, hostname, etc.
- # * $2: variable whose value to check if meets the requirements.
- local rgx_hostname='^[a-z][a-zA-Z0-9_-]+$' ;
- local rgx_inputbox_hostname="The hostname you just submitted isn't a valid name. Try with another name."
- local rgx_username='^[a-z][a-z0-9_-]+$' ;
- local rgx_inputbox_username="The username you just submitted isn't a valid name. Try with another name." ;
- eval rgx_name="$rgx_$1" ;
- eval rgx_inputbox="$rgx_inputbox_$1" ;
- eval name_ch="$$2" ;
- while [[ ! $name_ch =~ $rgx_name ]] ; do
- dialog --backtitle "$backtitle_var"
- --title "Wrong $1 submitted" --clear
- --inputbox "$rgx_inputbox" 0 0 2> name-ch ;
- name_ch=$(cat name-ch) ;
- rm name-ch ;
- done
- chckd_var="$name_ch" ;
- }
- dialog --backtitle "$backtitle_var"
- --title "Submit the username" --clear
- --inputbox "Which username do you want?" 0 0 2> user-name ;
- user_name=$(cat user-name) ;
- chck_rgx username user_name ;
- user_name=$chckd_var ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement