Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Strange behaviour in PATH with Cygwin #67

Closed
johnstevenson opened this issue Oct 16, 2012 · 2 comments
Closed

Strange behaviour in PATH with Cygwin #67

johnstevenson opened this issue Oct 16, 2012 · 2 comments

Comments

@johnstevenson
Copy link
Member

Discovered on Git For Windows (1.7.11). I have Cygwin installed and it is in my Path. When I append a new folder to my path, Git Bash will not find it unless it is suffixed with a semi-colon.

Cygwin, cmd.exe, and running Git/bin/sh.exe with no login, all find it.

  • If I remove Cygwin from my path, Git Bash finds it (with or without the trailing semicolon)
  • If I leave Cygwin in my path, I need to append a semi-colon for Git Bash to find it.

A quick hack is to alter the profile script and append a path separator:

if [ $MSYSTEM == MINGW32 ]; then
  export PATH=".:/usr/local/bin:/mingw/bin:/bin:$PATH:"
else
  export PATH=".:/usr/local/bin:/bin:/mingw/bin:$PATH:"
fi

Note that Git Bash shows the newly appended folder from env, but would not appear to use it.

Is this a general problem, or something to do with my own setup ?

@johnstevenson
Copy link
Member Author

Okay, further info. The problem exists only if the directory is the last entry in your path, which means it must be a USER path variable. The trick of adding a path-separator onto the end of it works because this is then interpreted as an empty path with a dot . and your last entry becomes the second-to-last entry.

I now understand that any paths to cygwin are removed from the PATH environment variable and I believe that the awk call made to do this causes the problem by appending an extra character (a null byte I think) in its result, which means the path cannot be resolved.

To demonstrate this, add the following to the profile script, immediately after the path has been set:

echo PATH length is ${#PATH}:
echo $PATH
echo

# run awk stripping non-existent parts
AWKEDPATH="$(awk -vRS=: -vORS=: '!/xxxxxxx/' <<< "$PATH")"
echo AWKEDPATH, nothing changed in PATH, length is ${#AWKEDPATH}:
echo $AWKEDPATH
echo

# remove trailing separator
AWKEDPATHREM="${AWKEDPATH%:}"

echo AWKEDPATHREM, removed trailing separator, length is ${#AWKEDPATHREM}:
echo $AWKEDPATHREM
echo

This essentially tells awk to remove a non-existent value xxxxxxx from the Path, then strips the trailing separator that this command adds. However the character-length of the path is increased by one.

Hope this helps.

@sschuberth
Copy link
Contributor

Fixed by the OP himself and the above pull request.

sschuberth added a commit that referenced this issue Oct 28, 2012
Using awk to strip any Cygwin path creates a null-byte at the end of the
string. This makes the last item in the path unresolvable and causes child
processes that are not dependent on msys-1.0.dll to inherit POSIX rather
than Windows paths. Fix this by not using awk at all.

Reported-by: John Stevenson <john-stevenson@blueyonder.co.uk>
Signed-off-by: Sebastian Schuberth <sschuberth@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants