繁体   English   中英

在Windows 10上使用cygwin和git bash的Shell脚本评估失败

[英]Shell script evaluation failing on windows 10 using cygwin and git bash

export testval='hdhhdhdh'
echo $testval
if [ ! -d ${testval} ]; then
echo -e "${RED}Please specify jettyScheduler as an environmental 
variable${RESET}"
exit
fi

即使在脚本中显式设置了testval,上述评估仍失败。 我有一台装有Windows 10操作系统的新笔记本电脑,在Windows 7上使用cygwin可以正常工作。 同样在Windows 10上使用cygwin和git bash失败。 有人可以帮忙吗?

您误解了test -d作用-它检查目录的存在,因此您所看到的是预期的(假设'hdhhdhdh'不是目录的名称)。 如您所见,如果您只是想检查是否设置了环境,那么test -z (或者相反是test -n )是完成此操作的一种方法。

PS:如果有可能包含空格,您还应该养成引用变量(“ $ testval”)的习惯。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM