如何在命令行上检查变量是否为空?

如何在命令行上检查变量是否为空?

我有以下脚本

echo "please enter user name: "
read USER_NAME

while [ ! "$USER_NAME" ]
do
echo "User name can't be empty please re-enter: "
read USER_NAME
done

如何使用命令行上的命令执行相同操作?

答案1

您可以使用while [ "$USER_NAME" == "" ] ...while [ -z $USER_NAME ]

相关内容