3
echo "Enter username"
read $WORD

if [[ "$WORD" =~ ^(Dale|Paul|Ray)$ ]]; then
    echo "$WORD is valid"
else
    echo "$WORD is invalid"
fi
  • I did format it like that, for some reason when I typed it here it changed. But it still doesn't work. – Maria C Jan 8 '17 at 12:58
6

The error is in read command, use read WORD instead of read $WORD.

Check this:

echo "Enter username"
read WORD

if [[ "$WORD" =~ ^(Dale|Paul|Ray)$ ]]; then
    echo "$WORD is valid"
else
    echo "$WORD is invalid"
fi

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.