Friendly Fella
Friendly Fella

Reputation: 75

Valid input in bash

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?

Upvotes: 0

Views: 60

Answers (1)

Amadan
Amadan

Reputation: 198486

read -e will interpret arrows correctly. From man bash:

-e If the standard input is coming from a terminal, readline (see READLINE 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)

Upvotes: 3

Related Questions