Automation, Orchestration, and Scripting

A script reads a variable named user and must accept it only if it starts with a lowercase letter and is followed by 2 to 7 lowercase letters or digits, with nothing else before or after. Which test does this in Bash?

Show the answer

Correct answerA. [[ $user =~ ^[a-z][a-z0-9]{2,7}$ ]]

The ^ and $ anchors force the whole string to fit the pattern, and an unquoted right side of =~ is treated as an extended regex. Without anchors, the match succeeds on any substring, so longer or malformed names would pass.