简体   繁体   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

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.

相关问题 Run a shell script using Cygwin bash instead of Git Bash for Windows from Eclipse - Run a shell script using Cygwin bash instead of Git Bash for Windows from Eclipse Git 状态在 cygwin 和 git bash(Windows 10)中给出不同的结果 - Git status gives different results in cygwin and git bash (windows 10) 在 Jenkins 中更改 Windows shell(从 Cygwin 到 Git Bash/msys) - Change Windows shell in Jenkins (from Cygwin to Git Bash/msys) 在 Git bash 在 ZAEA23489CE3AA9B6406EBB28E0CDA4 中全局运行 shell 脚本 - Run shell script globally in Git bash in Windows 使用python脚本打开Git Bash shell,然后在git bash shell中运行shell脚本 - Open Git Bash shell using a python script and then run a shell script in git bash shell Bash Shell 脚本未在 Windows 10 上使用 CMDER 查找文件,但适用于 ZEDC9F0A3A5D57498BF61 - Bash Shell Script is not finding files using CMDER on Windows 10 but works on Linux Echo 命令在 git bash 上的 shell 脚本中不起作用 - Echo command not working inside shell script on git bash for Windows ANSI 颜色不适用于使用 Windows 终端的 Windows 10 上的 Git Bash - ANSI color not working for Git Bash on Windows 10 using Windows Terminal Windows 7上的Git Bash中的Shell脚本 - Shell scripts in Git Bash on Windows 7 无法在Windows Cygwin中执行bash脚本 - Unable to execute bash script in windows cygwin
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM