Vyas Gupta
Vyas Gupta

Reputation: 13

Weird pwd glitch in .sh file

I am trying to set up DeepLab, and in the process I have to run a .sh file. Unfortunately, I must use Windows, so I am using Git Bash to run the file. Previously, I had Cygwin downloaded (since deleted). While running the .sh file, it uses pwd to run various commands, but it always errors because the pwd command when ran through the .sh file will return the path with /cygdrive/ prepending it. Any ideas on what might be happening?

Running pwd on Git Bash terminal gives the proper path (no /cygdrive/ at the beginning) and I have tried reinstalling cygdrive just to uninstall again. Not really sure where to go from here. I ran dos2unix after I edit the .sh file, so it shouldn't be an issue there.

Problematic code in the .sh file that I am running:

# 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

Running the .sh file in git bash gives the following output:

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

Notice that the echo ${CURRENT_DIR} prepends /cygdrive to the path desired.

Running pwd command in Git Bash gives the expected output:

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

Some other information:

$ 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

Upvotes: 1

Views: 186

Answers (1)

VonC
VonC

Reputation: 1328322

Try again in a CMD where you launch a git bash session after having set a simplified PATH (to avoid any lingering side-effect of an old 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%

(Modify C:\Path\to\Git and C:\Path\to\Python\Python36 by your Git and Python installation paths)

Then try again.

Upvotes: 0

Related Questions