This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Solving: Quotes in $PATH not translated properly


Hi,

a current problem when invoking cygwin is: if the Windows PATH
variable has quoted paths then cygwin won't translate those paths to
POSIX properly, so you end up with an incomplete $PATH:

T:\bin>echo %PATH%
"C:\Program Files\abc";[...]

T:\bin>sh
$ echo $PATH
"C:/Program Files/abc":[...]

No command is found in this directory. So I wrote this script:
(It just parses $PATH and translates every path between quotes
to POSIX and removes the quotes)

[begin parse_pathvar.sh]

TEST=`echo "$PATH" | sed "s/\\\\\\\\/\\\\\\\\\\\\\\\\/g"`
SHELLFILE="//t/bin/parse_pathvar_out.sh"
rm "$SHELLFILE"

awk -v mypath="$TEST" -v shellfile="$SHELLFILE" '
  BEGIN {
    if (index(mypath,"\"") > 0) {
      print "PATH=" > shellfile;
      parts=split(mypath,patharray,"\"");
      fixit=0;
      for (i=1; i<=parts; i+=1) {
        if (length(patharray[i]) > 0) {
          if (fixit == 1) {
            print "PATH=\"$PATH\"`cygpath -u \"" patharray[i] "\"`" >>
shellfile;
          }
          else {
            print "PATH=\"$PATH\"\"" patharray[i] "\"" >> shellfile;
          }
        }
        if (fixit == 1) {
          fixit=0;
        } else {
          fixit=1;
        }
      }
    }
  }
'

[end parse_pathvar.sh]
(I know, its ugly (: )
I include it in my profile like this:

# PATH handling. Quotes removing
/t/bin/parse_pathvar.sh
[ -f /t/bin/parse_pathvar_out.sh ] && source /t/bin/parse_pathvar_out.sh

So when I start a login bash everything is nice:

T:\src>bash --login

[/t/src] $ echo $PATH
/usr/local/bin:/usr/bin:/bin:/c/Program Files/abc:[...]

My remaining problem:
We launch a lot of scripts from the DOS Box, like 'sh script.sh'.
This doesn't invoke the profile. How can I launch this path-parser-script
every time a bash or ash gets started?
(Sorry if the question is a little off-topic, but the above script might
be useful to cygnus people. Customize the paths though)


bye,
 harry

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]