bash 中的有效输入

Valid input in bash

是否可以检查 bash 中输入的用户名是否有效?例如,使用 read 命令是否可以忽略或解释左箭头输入而不是将 ^[[D 存储在变量中? bash除了read还能用什么输入法?

read -e 将正确解释箭头。来自 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.

检查输入的字符串是否是有效的用户名是您的责任,因为它与输入无关(例如参见 [​​=16=])