echo "Enter username"
read $WORD
if [[ "$WORD" =~ ^(Dale|Paul|Ray)$ ]]; then
echo "$WORD is valid"
else
echo "$WORD is invalid"
fi
答案1
错误出现在read
命令中,请使用read WORD
而不是read $WORD
。
检查一下:
echo "Enter username"
read WORD
if [[ "$WORD" =~ ^(Dale|Paul|Ray)$ ]]; then
echo "$WORD is valid"
else
echo "$WORD is invalid"
fi