Is there anyway to check for a valid username input in bash? For example, using the read
command is there a way to ignore or interpret the left arrow input instead of storing ^[[D
in the variable? What other input method can be used in bash other than read
?
read -e
will interpret arrows correctly. From man bash
:
-e
If the standard input is coming from a terminal,readline
(seeREADLINE
above) is used to obtain the line. Readline uses the current (or default, if line editing was not previously active) editing settings.
Checking whether an input string is a valid username is your responsibility, as it has nothing to do with inputting (e.g. see Check Whether a User Exists)