.sh文件中的奇怪pwd故障

时间:2019-07-12 18:29:49

标签: shell cmd cygwin git-bash pwd

我正在尝试设置DeepLab,在此过程中,我必须运行.sh文件。不幸的是,我必须使用Windows,所以我正在使用Git Bash运行该文件。以前,我下载过Cygwin(已删除)。在运行.sh文件时,它使用pwd来运行各种命令,但是它总是会出错,因为pwd命令在运行.sh文件时会返回/ cygdrive /开头的路径。关于可能发生的事情有什么想法吗?

在Git Bash终端上运行pwd给出正确的路径(开头没有/ cygdrive /),我尝试重新安装cygdrive只是为了再次卸载。不太确定从这里去哪里。编辑.sh文件后,我运行了dos2unix,所以那里不应该有问题。

我正在运行的.sh文件中的问题代码:

# Set up the working environment.
CURRENT_DIR=$(pwd)
# added below line to see what pwd returned
echo ${CURRENT_DIR}
WORK_DIR="${CURRENT_DIR}/deeplab"

# Run model_test first to make sure the PYTHONPATH is correctly set.
python "${WORK_DIR}"/model_test.py -v

在git bash中运行.sh文件会给出以下输出:

guptav3@IMPH9074 MINGW64 /b/George/Vyas_Gupta/tensorflow/models/research/deeplab (master)
$ sh local_test.sh
/cygdrive/b/George/Vyas_Gupta/tensorflow/models/research
C:\Users\guptav3\AppData\Local\Continuum\anaconda3\python.exe: can't open file '/cygdrive/b/George/Vyas_Gupta/tensorflow/models/research/deeplab/model_test.py': [Errno 2] No such file or directory

请注意,回声$ {CURRENT_DIR}将/ cygdrive附加到所需的路径。

在Git Bash中运行pwd命令会提供预期的输出:

guptav3@IMPH9074 MINGW64 /b/George/Vyas_Gupta/tensorflow/models/research/deeplab (master)
$ pwd
/b/George/Vyas_Gupta/tensorflow/models/research/deeplab

其他一些信息:

$ ldd $(which pwd)
        ntdll.dll => /cygdrive/c/windows/SYSTEM32/ntdll.dll (0x77c90000)
        kernel32.dll => /cygdrive/c/windows/system32/kernel32.dll (0x77a70000)
        KERNELBASE.dll => /cygdrive/c/windows/system32/KERNELBASE.dll (0x7fefd8d0000)
        SYSFER.DLL => /cygdrive/c/windows/System32/SYSFER.DLL (0x754c0000)
        ADVAPI32.dll => /cygdrive/c/windows/system32/ADVAPI32.dll (0x7feff910000)
        msvcrt.dll => /cygdrive/c/windows/system32/msvcrt.dll (0x7fefe9d0000)
        sechost.dll => /cygdrive/c/windows/SYSTEM32/sechost.dll (0x7fefef80000)
        RPCRT4.dll => /cygdrive/c/windows/system32/RPCRT4.dll (0x7feffcf0000)
        msys-intl-8.dll => /cygdrive/c/Program Files/Git/usr/bin/msys-intl-8.dll (0x430b30000)
        msys-iconv-2.dll => /cygdrive/c/Program Files/Git/usr/bin/msys-iconv-2.dll (0x5603f0000)
        msys-2.0.dll => /cygdrive/c/Program Files/Git/usr/bin/msys-2.0.dll (0x180040000)
        DNSAPI.dll => /cygdrive/c/windows/system32/DNSAPI.dll (0x7fefcdb0000)
        WS2_32.dll => /cygdrive/c/windows/system32/WS2_32.dll (0x7feffc90000)
        NSI.dll => /cygdrive/c/windows/system32/NSI.dll (0x7feffce0000)

$ printenv | grep cygdrive
PATH=/usr/bin:/cygdrive/c/Program Files/Git/mingw64/bin:/cygdrive/c/Program Files/Git/usr/local/bin:/cygdrive/c/Program Files/Git/usr/bin:/cygdrive/c/Program Files/Git/usr/bin:/cygdrive/c/Program Files/Git/mingw64/bin:/cygdrive/c/Program Files/Git/usr/bin:/usr/bin:/cygdrive/c/Program Files (x86)/Common Files/Oracle/Java/javapath:/cygdrive/c/ProgramData/Oracle/Java/javapath:/cygdrive/c/Program Files (x86)/Intel/iCLS Client:/cygdrive/c/Program Files/Intel/iCLS Client:/cygdrive/c/windows/system32:/cygdrive/c/windows:/cygdrive/c/windows/System32/Wbem:/cygdrive/c/windows/System32/WindowsPowerShell/v1.0:/cygdrive/c/Program Files (x86)/Intel/Intel(R) Management Engine Components/DAL:/cygdrive/c/Program Files/Intel/Intel(R) Management Engine Components/DAL:/cygdrive/c/Program Files (x86)/Intel/Intel(R) Management Engine Components/IPT:/cygdrive/c/Program Files/Intel/Intel(R) Management Engine Components/IPT:/cygdrive/c/Program Files (x86)/HP/HP Performance Advisor:/cygdrive/c/Program Files/MATLAB/R2018b/runtime/win64:/cygdrive/c/Program Files/MATLAB/R2018b/bin:/cygdrive/c/Program Files/MATLAB/R2017b/runtime/win64:/cygdrive/c/Program Files/MATLAB/R2017b/bin:/cygdrive/c/Program Files/MATLAB/R2017a/runtime/win64:/cygdrive/c/Program Files/MATLAB/R2017a/bin:/cygdrive/c/Program Files/MATLAB/R2016a/runtime/win64:/cygdrive/c/Program Files/MATLAB/R2016a/bin:/cygdrive/c/Program Files/Git/cmd:/cygdrive/c/Program Files (x86)/Webex/Webex/Applications:/AppData/Local/Programs/Python/Launcher:/cygdrive/c/Program Files/Git/usr/bin/vendor_perl:/cygdrive/c/Program Files/Git/usr/bin/core_perl

1 个答案:

答案 0 :(得分:0)

在CMD中重试一次,在该命令中,您设置了简化的PATH后将启动git bash会话(以避免旧PATH的任何挥之不去的副作用)

set PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem
set GIT_HOME=C:\Path\to\Git
set PATH=%GIT_HOME%;%GIT_HOME%\bin;%GIT_HOME%\usr\bin;%PATH%
SET PATH=C:\Path\to\Python\Python36;%PATH%

(通过Git和Python安装路径修改C:\Path\to\GitC:\Path\to\Python\Python36

然后重试。