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]

Re: BUG: base-files-2.2-1 profile.d runs in subshell - sourced filesfail


On Mon, 25 Aug 2003, mike808 wrote:

> In base-files-2.2-1, the following was recently changed:
>
> > # Run all of the profile.d scripts
> > # Note that these are supplied by separate packages
> > /bin/find /etc/profile.d -iname '*.sh' -type f | while read f; do
> >   if [ -f "$f" ]; then
> >     . "$f"
> >   fi
> > done
>
> Previously, the find was executed as an expanded filename wildcard
> expansion as part of a 'for' loop. (c.f. 2.0-2)
>
> When this was changed to the current code, because a pipe is used,
> the subsequent commands run in a *sub-shell* of the parent /etc/profile
> script executing. This means that any environment changes performed
> by the files in /etc/profile.d/ are *lost* when the sub-shell returns
> to the parent.
>
> This effectively nullifies any environment changes being performed in
> those files. Things like PATH setting, etc. I use them to clean up
> environment variables mangled by Rational prior to setting up a shell
> in Cygwin.
>
> Please put it back to the way it was in base-files-2.0-2, with
> the one exception that quote marks be placed around the "$i" iterator
> variable so as to preserve any whitespace that might be in the filenames.
>
> I have corrected that working code (from 2.0-2) below:
>
> > # Run all of the profile.d scripts
> > # Note that these are supplied by separate packages
> > for i in /etc/profile.d/*.sh ; do
> >   if [ -f "$i" ]; then
> >     . "$i"
> >   fi
> > done
>
> Thank you.
> Michael/

Michael,

Your code above will not find the same files as what's currently in
/etc/profile.  The correct code (with no subshells) is included below.

# Run all of the profile.d scripts
# Note that these are supplied by separate packages
while read f; do
  if [ -f "$f" ]; then
    . "$f"
  fi
done << EOF
`/bin/find /etc/profile.d -iname '*.sh' -type f`
EOF

Hope this helps,
	Igor
P.S. While investigating this, I found that /etc/profile.d/mc.sh uses the
'alias' command which /bin/sh doesn't recognize.  Pavel, please take note.
-- 
				http://cs.nyu.edu/~pechtcha/
      |\      _,,,---,,_		pechtcha@cs.nyu.edu
ZZZzz /,`.-'`'    -.  ;-;;,_		igor@watson.ibm.com
     |,4-  ) )-,_. ,\ (  `'-'		Igor Pechtchanski, Ph.D.
    '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

"I have since come to realize that being between your mentor and his route
to the bathroom is a major career booster."  -- Patrick Naughton

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.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]