我正在从 VMware Tools 检索主机名并尝试评估我的脚本中是否存在两个变量:
selection=2
# Check if hostname is present in guestinfo
hostname="$(vmtoolsd --cmd "info-get guestinfo.startup.hostname")"
if [[ "$selection" = 2 && ! -z ${hostname+x} ]]
then
echo "Args present."
else
echo "Args NOT present."
fi
无论是否在 VMX 配置文件中设置了主机名值,if 语句都会返回“Args present”。
我相信这是因为执行了 vmtoolsd 命令,这意味着“主机名”变量不为空。不确定如何修复。
怎么了?