public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* /etc/profile: avoid multiple /usr/bin in PATH
@ 2015-12-06 22:47 Helmut Karlowski
  2015-12-08 21:01 ` Achim Gratz
  2016-09-04 11:32 ` Achim Gratz
  0 siblings, 2 replies; 12+ messages in thread
From: Helmut Karlowski @ 2015-12-06 22:47 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 306 bytes --]

Hello,

I set C:/cygwin/usr/bin in my windows-environment. Now /etc/profile always  
adds /usr/bin to PATH resulting in /usr/bin being twice in my cygwin-PATH.

The attached patch fixes this.

It also sets SHELL if not yet set and avoids a call of hostname.


Maybe the maintainer takes a look.

-Helmut
--

[-- Attachment #2: profile.diff --]
[-- Type: application/octet-stream, Size: 2347 bytes --]

--- defaults/etc/profile	2015-09-26 09:45:02.000000000 +0200
+++ profile	2015-12-06 23:44:38.715400000 +0100
@@ -5,7 +6,7 @@
 # with this software.
 # If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
 
-# base-files version 4.2-4
+# base-files version 4.2-3
 
 # /etc/profile: executed by the command interpreter for login shells.
 
@@ -31,12 +32,27 @@
   # software to override 'system' software.
   # Modifying these default path settings can be done in different ways.
   # To learn more about startup files, refer to your shell's man page.
-
-  : ${ORIGINAL_PATH=${PATH}}
+	# add /usr/bin,/usr/local/bin to PATH.
   if [ ${CYGWIN_NOWINPATH-addwinpath} = "addwinpath" ] ; then
-    PATH="/usr/local/bin:/usr/bin${PATH:+:${PATH}}"
+		# avoid multiple path-entries.
+		ifs="$IFS"
+		IFS=:
+		path_localbin=/usr/local/bin
+		path_bin=/usr/bin
+		for p in $PATH; do
+			[ -n "$path_localbin" -a "$p" = "$path_localbin" ] && path_localbin=
+			[ -n "$path_bin" -a "$p" = "$path_bin" ] && path_bin=
+		done
+		: ${ORIGINAL_PATH=${PATH}}
+		if [ -z "$path_bin" -o -z "$path_localbin" ]; then
+			# append :
+			[ -n "$path_localbin" -a -n "$path_bin$PATH" ] && path_localbin=$path_localbin:
+			[ -n "$path_bin" -a -n "$PATH" ] && path_bin=$path_bin:
+			PATH="$path_localbin$path_bin$PATH"
+		fi
+		IFS="$ifs"
   else
-    PATH="/usr/local/bin:/usr/bin"
+		PATH="$path_localbin:$path_bin"
   fi
 
 # see https://cygwin.com/ml/cygwin/2014-05/msg00352.html
@@ -111,6 +127,9 @@
   cd "${HOME}" || echo "WARNING: Failed attempt to cd into ${HOME}!"
 fi
 
+# set default-SHELL
+: ${SHELL:=/bin/sh}
+
 # Shell dependent settings
 profile_d ()
 {
@@ -138,7 +157,7 @@
 if [ ! "x${BASH_VERSION}" = "x"  ]; then
   [ -f "/etc/bash.bashrc" ] && . "/etc/bash.bashrc"
 elif [ ! "x${KSH_VERSION}" = "x" ]; then
-  typeset -l HOSTNAME="$(/usr/bin/hostname)"
+	typeset -l HOSTNAME
   [ "${PS1-null}" = "null" ] || PS1=$(print '\033]0;${PWD}\n\033[32m${USER}@${HOSTNAME} \033[33m${PWD/${HOME}/~}\033[0m\n$ ')
 elif [ ! "x${ZSH_VERSION}" = "x" ]; then
   # zsh is in shell compatibility mode here, so we probably shouldn't do this
@@ -151,3 +170,4 @@
 
 # export PROFILEREAD PATH ORIGINAL_PATH MANPATH INFOPATH USER TMP TEMP PRINTER HOSTNAME PS1 SHELL tmp temp
 export PROFILEREAD PATH ORIGINAL_PATH INFOPATH USER TMP TEMP PRINTER HOSTNAME PS1 SHELL
+

[-- Attachment #3: Type: text/plain, Size: 218 bytes --]

--
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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: /etc/profile: avoid multiple /usr/bin in PATH
  2015-12-06 22:47 /etc/profile: avoid multiple /usr/bin in PATH Helmut Karlowski
@ 2015-12-08 21:01 ` Achim Gratz
  2015-12-08 21:17   ` Helmut Karlowski
  2016-09-04 11:32 ` Achim Gratz
  1 sibling, 1 reply; 12+ messages in thread
From: Achim Gratz @ 2015-12-08 21:01 UTC (permalink / raw)
  To: cygwin

Helmut Karlowski writes:
> I set C:/cygwin/usr/bin in my windows-environment. Now /etc/profile
> always adds /usr/bin to PATH resulting in /usr/bin being twice in my
> cygwin-PATH.
>
> The attached patch fixes this.

I tend to reject this patch.  The purpose of the default profile is to
put those two paths in front, while with your patch they could end up
anywhere.  If you think that's OK for you, then you can already do that,
but I don't think that's a good default.

> It also sets SHELL if not yet set and avoids a call of hostname.

Can you tell me in which circumstances this happens and why this is a
problem?  SHELL is supposed to be the user preference, so I don't think
/etc/profile should try to second-guess it.

The second fork to hostname can indeed be removed.


Regards,
Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

Factory and User Sound Singles for Waldorf rackAttack:
http://Synth.Stromeko.net/Downloads.html#WaldorfSounds

--
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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: /etc/profile: avoid multiple /usr/bin in PATH
  2015-12-08 21:01 ` Achim Gratz
@ 2015-12-08 21:17   ` Helmut Karlowski
  2015-12-08 21:21     ` Achim Gratz
  0 siblings, 1 reply; 12+ messages in thread
From: Helmut Karlowski @ 2015-12-08 21:17 UTC (permalink / raw)
  To: cygwin

Am 08.12.2015, 22:01 Uhr, schrieb Achim Gratz:

> Helmut Karlowski writes:
>> I set C:/cygwin/usr/bin in my windows-environment. Now /etc/profile
>> always adds /usr/bin to PATH resulting in /usr/bin being twice in my
>> cygwin-PATH.
>>
>> The attached patch fixes this.
>
> I tend to reject this patch.  The purpose of the default profile is to
> put those two paths in front, while with your patch they could end up
> anywhere.  If you think that's OK for you, then you can already do that,

Not if they have not been present in the windows-path before. I personally  
want to keep the order I have in my windows-path, but tastes may differ.  
But the actual reason for me to change profile was that I had /usr/bin  
twice in my cygwin-path. That can be avoided with the original profile if  
the user also sets CYGWIN_NOWINPATH to something in the  
windows-environment, which I escaped me before, and then I would also have  
to set /usr/local/bin in windows. I find this overcomplicated for the user.

To force /usr/bin first in PATH would be doable of course.

> but I don't think that's a good default.
>
>> It also sets SHELL if not yet set and avoids a call of hostname.
>
> Can you tell me in which circumstances this happens and why this is a
> problem?  SHELL is supposed to be the user preference, so I don't think
> /etc/profile should try to second-guess it.

/etc/profile is run before ~/.profile, and if that does not set SHELL  
there will be none.

-Helmut

--

--
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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: /etc/profile: avoid multiple /usr/bin in PATH
  2015-12-08 21:17   ` Helmut Karlowski
@ 2015-12-08 21:21     ` Achim Gratz
  2015-12-08 21:26       ` Helmut Karlowski
  0 siblings, 1 reply; 12+ messages in thread
From: Achim Gratz @ 2015-12-08 21:21 UTC (permalink / raw)
  To: cygwin

Helmut Karlowski writes:
>> Can you tell me in which circumstances this happens and why this is a
>> problem?  SHELL is supposed to be the user preference, so I don't think
>> /etc/profile should try to second-guess it.
>
> /etc/profile is run before ~/.profile, and if that does not set SHELL
> there will be none.

Yes, but why is this a problem?  Note that bash will set it anyway if
not present.


Regards,
Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

Wavetables for the Waldorf Blofeld:
http://Synth.Stromeko.net/Downloads.html#BlofeldUserWavetables

--
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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: /etc/profile: avoid multiple /usr/bin in PATH
  2015-12-08 21:21     ` Achim Gratz
@ 2015-12-08 21:26       ` Helmut Karlowski
  2015-12-08 21:31         ` Helmut Karlowski
  0 siblings, 1 reply; 12+ messages in thread
From: Helmut Karlowski @ 2015-12-08 21:26 UTC (permalink / raw)
  To: cygwin

Am 08.12.2015, 22:21 Uhr, schrieb Achim Gratz:

> Helmut Karlowski writes:
>>> Can you tell me in which circumstances this happens and why this is a
>>> problem?  SHELL is supposed to be the user preference, so I don't think
>>> /etc/profile should try to second-guess it.
>>
>> /etc/profile is run before ~/.profile, and if that does not set SHELL
>> there will be none.
>
> Yes, but why is this a problem?  Note that bash will set it anyway if
> not present.

There must have been one once, I don't remember. And I don't use bash:

881/etc$bash --version
aKSH v0.0.1, Dec  7 2015 (cygwin-1.7.35(0.287/5/3))

(selfmade).

-Helmut


--
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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: /etc/profile: avoid multiple /usr/bin in PATH
  2015-12-08 21:26       ` Helmut Karlowski
@ 2015-12-08 21:31         ` Helmut Karlowski
  2015-12-08 21:59           ` Helmut Karlowski
  0 siblings, 1 reply; 12+ messages in thread
From: Helmut Karlowski @ 2015-12-08 21:31 UTC (permalink / raw)
  To: cygwin

Am 08.12.2015, 22:26 Uhr, schrieb Helmut Karlowski:

> Am 08.12.2015, 22:21 Uhr, schrieb Achim Gratz:
>
>> Helmut Karlowski writes:
>>>> Can you tell me in which circumstances this happens and why this is a
>>>> problem?  SHELL is supposed to be the user preference, so I don't  
>>>> think
>>>> /etc/profile should try to second-guess it.
>>>
>>> /etc/profile is run before ~/.profile, and if that does not set SHELL
>>> there will be none.
>>
>> Yes, but why is this a problem?  Note that bash will set it anyway if
>> not present.

All shells set it only when run as login-shell.

-Helmut


--

--
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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: /etc/profile: avoid multiple /usr/bin in PATH
  2015-12-08 21:31         ` Helmut Karlowski
@ 2015-12-08 21:59           ` Helmut Karlowski
  0 siblings, 0 replies; 12+ messages in thread
From: Helmut Karlowski @ 2015-12-08 21:59 UTC (permalink / raw)
  To: cygwin

Am 08.12.2015, 22:31 Uhr, schrieb Helmut Karlowski:

>>> Yes, but why is this a problem?  Note that bash will set it anyway if
>>> not present.
>
> All shells set it only when run as login-shell.

Wrong: Only bash gives it a value - ksh and dash export SHELL with no  
value if none present. And IMHO SHELL should not be /bin/bash by default.

-Helmut

--

--
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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: /etc/profile: avoid multiple /usr/bin in PATH
  2015-12-06 22:47 /etc/profile: avoid multiple /usr/bin in PATH Helmut Karlowski
  2015-12-08 21:01 ` Achim Gratz
@ 2016-09-04 11:32 ` Achim Gratz
  2016-09-05  4:08   ` Doug Henderson
  1 sibling, 1 reply; 12+ messages in thread
From: Achim Gratz @ 2016-09-04 11:32 UTC (permalink / raw)
  To: cygwin

Helmut Karlowski writes:
> I set C:/cygwin/usr/bin in my windows-environment. Now /etc/profile
> always adds /usr/bin to PATH resulting in /usr/bin being twice in my
> cygwin-PATH.
>
> The attached patch fixes this.

I've added the option to just use the already set-up PATH variable from
Windows for this use case.  Set CYGWIN_USEWINPATH before starting up.


Regards,
Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

Waldorf MIDI Implementation & additional documentation:
http://Synth.Stromeko.net/Downloads.html#WaldorfDocs

--
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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: /etc/profile: avoid multiple /usr/bin in PATH
  2016-09-04 11:32 ` Achim Gratz
@ 2016-09-05  4:08   ` Doug Henderson
  2016-09-05 17:57     ` Achim Gratz
  0 siblings, 1 reply; 12+ messages in thread
From: Doug Henderson @ 2016-09-05  4:08 UTC (permalink / raw)
  To: cygwin

On 4 September 2016 at 05:32, Achim Gratz wrote:
> Helmut Karlowski writes:
>> I set C:/cygwin/usr/bin in my windows-environment. Now /etc/profile
>> always adds /usr/bin to PATH resulting in /usr/bin being twice in my
>> cygwin-PATH.
>>
>> The attached patch fixes this.
>
> I've added the option to just use the already set-up PATH variable from
> Windows for this use case.  Set CYGWIN_USEWINPATH before starting up.
>

Please make sure that this version of cygwin.bat will work correctly
when CYGWIN_NOWINPATH=1 is set in the windows environment.

I use this to isolate my cygwin environment from random windows stuff.
When I need to execute windows executables, I wrap the call in a
script or alias that makes just enough of the window's path available
to let it work.

This makes it much safer when running multiple cygwins, intentionally
for 32bit and 64bit, or unintentionally as when running windows apps
that include a cygwin.dll, e.g. GitHub for Windows. Also it avoids
accidentally running non-cygwin versions of *nix programs such as can
happen when you have Gnu for Windows or MSYS in your windows path.

Note that CYGWIN_NOWINPATH is still undocumented, except in the email
archives. See, e.g.

    https://www.google.ca/search?q=CYGWIN_NOWINPATH+site:cygwin.com

CYGWIN_USEWINPATH is also undocumented, except in a non-cygwin.com
email archive.

Thanks,
Doug

-- 
Doug Henderson, Calgary, Alberta, Canada

--
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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: /etc/profile: avoid multiple /usr/bin in PATH
  2016-09-05  4:08   ` Doug Henderson
@ 2016-09-05 17:57     ` Achim Gratz
  2016-09-05 18:13       ` Vince Rice
  0 siblings, 1 reply; 12+ messages in thread
From: Achim Gratz @ 2016-09-05 17:57 UTC (permalink / raw)
  To: cygwin

Doug Henderson writes:
> Please make sure that this version of cygwin.bat will work correctly
> when CYGWIN_NOWINPATH=1 is set in the windows environment.

So test the test version and tell me if it still works for you?

> Note that CYGWIN_NOWINPATH is still undocumented, except in the email
> archives. See, e.g.
>
>     https://www.google.ca/search?q=CYGWIN_NOWINPATH+site:cygwin.com
>
> CYGWIN_USEWINPATH is also undocumented, except in a non-cygwin.com
> email archive.

It's documented right in /etc/profile for the moment.


Regards,
Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

SD adaptations for KORG EX-800 and Poly-800MkII V0.9:
http://Synth.Stromeko.net/Downloads.html#KorgSDada

--
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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: /etc/profile: avoid multiple /usr/bin in PATH
  2016-09-05 17:57     ` Achim Gratz
@ 2016-09-05 18:13       ` Vince Rice
  2016-09-05 19:07         ` Achim Gratz
  0 siblings, 1 reply; 12+ messages in thread
From: Vince Rice @ 2016-09-05 18:13 UTC (permalink / raw)
  To: Achim Gratz; +Cc: cygwin

>> Note that CYGWIN_NOWINPATH is still undocumented, except in the email
>> archives. See, e.g.
>> 
>>    https://www.google.ca/search?q=CYGWIN_NOWINPATH+site:cygwin.com
>> 
>> CYGWIN_USEWINPATH is also undocumented, except in a non-cygwin.com
>> email archive.
> 
> It's documented right in /etc/profile for the moment.

Well, “documented” is a little strong. “Used” is more accurate. There are no comments as to what it is or what it’s used for, at least in my /etc/profile (last updated in June).


--
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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: /etc/profile: avoid multiple /usr/bin in PATH
  2016-09-05 18:13       ` Vince Rice
@ 2016-09-05 19:07         ` Achim Gratz
  0 siblings, 0 replies; 12+ messages in thread
From: Achim Gratz @ 2016-09-05 19:07 UTC (permalink / raw)
  To: cygwin

Vince Rice writes:
>> It's documented right in /etc/profile for the moment.
>
> Well, “documented” is a little strong. “Used” is more accurate. There
> are no comments as to what it is or what it’s used for, at least in my
> /etc/profile (last updated in June).

In case it wasn't clear, I was talking about the test version.

https://sourceware.org/git/?p=cygwin-apps/base-files.git;a=blob;f=etc/defaults/etc/profile


Regards,
Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

DIY Stuff:
http://Synth.Stromeko.net/DIY.html

--
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

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2016-09-05 19:07 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-06 22:47 /etc/profile: avoid multiple /usr/bin in PATH Helmut Karlowski
2015-12-08 21:01 ` Achim Gratz
2015-12-08 21:17   ` Helmut Karlowski
2015-12-08 21:21     ` Achim Gratz
2015-12-08 21:26       ` Helmut Karlowski
2015-12-08 21:31         ` Helmut Karlowski
2015-12-08 21:59           ` Helmut Karlowski
2016-09-04 11:32 ` Achim Gratz
2016-09-05  4:08   ` Doug Henderson
2016-09-05 17:57     ` Achim Gratz
2016-09-05 18:13       ` Vince Rice
2016-09-05 19:07         ` Achim Gratz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).