[英]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
The above evaluation is failing eventhough testval is set explicity in the script . 即使在脚本中显式设置了testval,上述评估仍失败。 I got a new laptop with windows 10 OS , the above was working fine using cygwin on Windows 7 .
我有一台装有Windows 10操作系统的新笔记本电脑,在Windows 7上使用cygwin可以正常工作。 The same is failing using cygwin & git bash on windows 10 .
同样在Windows 10上使用cygwin和git bash失败。 Can someone help ?
有人可以帮忙吗?
You've misunderstood what test -d
does - it checks for existence of a directory, so what you see is expected (assuming that 'hdhhdhdh' isn't the name of a directory). 您误解了
test -d
作用-它检查目录的存在,因此您所看到的是预期的(假设'hdhhdhdh'不是目录的名称)。 If you just want to check if an environment is set, then test -z
(or conversely test -n
) is one way to do it, as you have seen. 如您所见,如果您只是想检查是否设置了环境,那么
test -z
(或者相反是test -n
)是完成此操作的一种方法。
PS You should also get into the habit of quoting variables ("$testval") if there's any possibility it may contain spaces. PS:如果有可能包含空格,您还应该养成引用变量(“ $ testval”)的习惯。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.