delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2011/02/01/17:41:06

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-1.3 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SARE_FREE_WEBM_LAPOSTE,T_RP_MATCHES_RCVD,T_TO_NO_BRKTS_FREEMAIL
X-Spam-Check-By: sourceware.org
Message-ID: <4D488C09.7050606@laposte.net>
Date: Tue, 01 Feb 2011 23:41:13 +0100
From: Cyrille Lefevre <cyrille DOT lefevre-lists AT laposte DOT net>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.8.1.3) Gecko/20070326 Thunderbird/2.0.0.0 Mnenhy/0.7.5.666
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: bad PATH conversion under XP
References: <4D3F6779 DOT 5010100 AT laposte DOT net> <4D3F8295 DOT 2020109 AT cpan DOT org>
In-Reply-To: <4D3F8295.2020109@cpan.org>
X-me-spamlevel: not-spam
X-me-spamrating: 34.799999
X-me-spamcause: OK, (-130)(0000)gggruggvucftvghtrhhoucdtuddrfeduvddrtddvucetggdotefuucfrrhhofhhilhgvmecuoehnohhnvgeqnecuuegrihhlohhuthemuceftddtnecuucdlqddutddtmdenshgvthhtihhnghhsucdlqdeftddm
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

--------------070401050005040003090004
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: quoted-printable

Le 26/01/2011 03:10, Rafael Kitover a =E9crit :
>
> On 1/25/2011 7:14 PM, Cyrille Lefevre wrote:
>> v2$ uname -a
>> CYGWIN_NT-5.1 PC213736 1.7.7(0.230/5/3) 2010-08-31 09:58 i686 Cygwin
>>
>> aka
>>
>> Windows XP Professional Ver 5.1 Build 2600 Service Pack 3
>>
>> though SSH at least :
>>
>> v2$ regtool get /machine/SYSTEM/CurrentControlSet/Control/Session\
>> Manager/Environment/PATH
>> %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\orawin\=
BIN;C:\Program
>>
>> Files\ATI Technologies\ATI Control Panel;"C:\Program
>> Files\Hummingbird\Connectivity\7.00\Accessories\";C:\Program
>> Files\QuickTime\QTSystem\;D:\sfu\Perl\bin\;D:\sfu\common\;C:\WINDOWS\sys=
tem32\WindowsPowerShell\v1.0\;C:\Program
>>
>> Files\Samsung\Samsung PC Studio 3\
>>
>> gives :
>>
>> /usr/local/bin:/usr/bin:/bin:/cygdrive/c/WINDOWS/system32:/cygdrive/c/WI=
NDOWS:/cygdrive/c/WINDOWS/System32/Wbem:/cygdrive/c/orawin/BIN:/cygdrive/c/=
Program
>>
>> Files/ATI Technologies/ATI Control Panel:"C:/Program
>> Files/Hummingbird/Connectivity/7.00/Accessories/":/cygdrive/c/Program
>> Files/QuickTime/QTSystem/:/cygdrive/d/sfu/Perl/bin/:/cygdrive/d/sfu/comm=
on/:/cygdrive/c/WINDOWS/system32/WindowsPowerShell/v1.0/:/cygdrive/c/Program
>>
>> Files/Samsung/Samsung PC Studio 3/:/bin
>>
>> note the unconverted path between double-quotes :
>>
>> "C:/Program Files/Hummingbird/Connectivity/7.00/Accessories/"
>
> I saw this problem on msys, I think it applies to cygwin as well.
>
> If you just go into environment under advanced system settings in
> control panel and remove the double quotes, it will work correctly. I'm
> on Windows 7.

don't be kidding ! ok, I'm joking...

I'm reporting a cygwin bug...
of course I know I could edit the windows environment variables.
however, this problem has to be fixed.

>>
>> also, how about to get rid of final slashes (.../ =3D> ...) ?
>
> You could reprocess your PATH in your .bashrc, but the final slashes
> should have no effect on how the PATH is actually used...

everything is possible at shell level, even more efficiently, but since=20
the path is working by the cygwin layer, why not to clean things up.

PS : no fork cleanups...

# space tab newline
_IFS=3D${IFS:-'=20=09
'}
IFS=3D':'

# clean up final /'es
_PATH=3D _sep=3D
for _path in $PATH; do
case $path in */) _path=3D${_path#/} ;; esac
_PATH=3D${_PATH}${_sep}${_path}
_sep=3D':'
done
PATH=3D${_PATH}

# cleanup twins
_PATH=3D _sep=3D
for _path in $PATH; do
case ":${_PATH}:" in
*":${_path}:"*) ;;
*) _PATH=3D${_PATH}${_sep}${_path}; _sep=3D':' ;;
esac
done
PATH=3D${_PATH}

# not necessary, but...
# cleanup windows paths w/ space
_PATH=3D _sep=3D
for _path in $PATH; do
case ":${_path}:" in
*' '*) ;;
*) _PATH=3D${_PATH}${_sep}${_path}; _sep=3D':' ;;
esac
done
PATH=3D${_PATH}

IFS=3D${_IFS}
unset _IFS _PATH _path _sep

untested but should work...
of course, you may do this in one loop only !

also, I reworked my version of ssh-session-env.sh

Regards,

Cyrille Lefevre
--=20
mailto:Cyrille DOT Lefevre-lists AT laposte DOT net

--------------070401050005040003090004
Content-Type: text/plain;
 name="ssh-session-env.sh"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="ssh-session-env.sh"

#!/bin/sh
#
# ssh-session-env.sh - script for installation in /etc/profile.d
#
# because in sessions started from sshd the windows system environment
# variables in general are not set except for some which are possible
# special handled (like PATH, etc.) and the windows user environment
# variables are not set from the actual user but from the user of the
# sshd server this script is used to build this environment settings in
# shells with bournish syntax which uses /etc/profile for initialization.
#
# authors: Kurt Franke, Cyrille Lefevre
#
# date:   26 january 2011

if ps -fp ${PPID} | grep -q "/usr/sbin/sshd$"; then
	_SECONDS_=${SECONDS:-$(date +%s)}
	_IFS_=${IFS}
	IFS='
'
	eval "$( (
	regtool -qv list /machine/SYSTEM/CurrentControlSet/Control/Session\ Manager/Environment
	regtool -qv list /user/Environment
	regtool -qv list /user/Volatile\ Environment
	) |
	awk -v q="'" -v mp="$(mount --show-cygdrive-prefix)" '
function s2a(str, a, sep,	i, t) {
	if (sep == "") sep = " +"
	split(str, t, sep)
	for (i in t) a[t[i]] = ""
}
function uniqp(p,	i, j, k, o, n, a, s) {
	k = split(p, o, ":")
	for (i = j = 1; i <= k; i++)
		if (!(tolower(o[i]) in a))
			a[tolower(n[j++] = o[i])] = ""
	p = s = ""
	for (i = 1; i < j; i++) {
		p = p s n[i]
		s = ":"
	}
	return p
}
BEGIN {
	s2a("APPDATA CLASSPATH QTJAVA LOCALAPPDATA USERPROFILE VS90COMNTOOLS", \
	    noconvert)
	s2a("HOMEPATH PATH TEMP TMP", override)
	sub(/.*\n/, "", mp)
	sub(/[ \t].*/, "", mp)
}
! /\\ \(\)$/ {
	var = toupper($1)
	$1 = $2 = $3 = ""
	sub("^ +", "")
	environ[var] = var == "PATH" && var in environ ? \
		environ[var] ";" $0 : $0
}
END {
	flag = 1
	while (flag) {
		flag = 0
		for (var in environ) {
			val = environ[var]
			if (match(val,/%[^%]+%/)) {
				flag = 1
				subvar = substr(val, RSTART+1, RLENGTH-2)
				subvar = toupper(subvar)
				subval = subvar in environ ? \
					environ[subvar] : ENVIRON[subvar]
				if (subval !~ /%[^%]%/) {
					head = substr(val, 1, RSTART-1)
					tail = substr(val, RSTART+RLENGTH)
					environ[var] = head subval tail
				}
			}
		}
	}
	for (var in environ) {
		if (!(var in override) && var in ENVIRON)
			continue
		val = environ[var]
		if (!(var in noconvert) && (val ~ /;/ || val ~ /^"?.:/)) {
			gsub(/([a-zA-Z]):/, mp "/&", val)
			gsub(/\\/,"/",val)
			gsub(/[:"]|\/$/,"",val)
			gsub(/\/?;/,":",val)
		}
		if (var == "PATH") {
			gsub(/"([a-zA-Z]):/, mp "/&", ENVIRON[var])
			gsub(/"|\/$/,"",ENVIRON[var])
			gsub(/\/:/,":",ENVIRON[var])
			val = uniqp(ENVIRON[var] ":" val)
		}
		gsub(q, "\\"q, val)
		print "export", var "="q val q
	}
}
')"
	echo "elapsed: $(( ${SECONDS:-$(date +%s)} - $_SECONDS_ ))s"
	IFS=${_IFS_}
	unset _IFS_ _SECONDS_
fi

# eof


--------------070401050005040003090004
Content-Type: text/plain; charset=us-ascii

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
--------------070401050005040003090004--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019