.sh 文件中的奇怪密码故障

Weird pwd glitch in .sh file

我正在尝试设置 DeepLab,在此过程中我必须 运行 一个 .sh 文件。不幸的是,我必须使用 Windows,所以我使用 Git Bash 来 运行 文件。以前,我下载了 Cygwin(已删除)。 运行在.sh文件中使用pwd来运行各种命令,但是总是报错,因为运行通过.sh文件的pwd命令会return带有 /cygdrive/ 前缀的路径。对可能发生的事情有什么想法吗?

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

我正在 运行ning:

.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

请注意 echo ${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

在 CMD 中再次尝试启动 git bash 会话 设置简化的路径(以避免任何挥之不去的 side-effect 旧路径)

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

然后重试。