[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: /etc/profile.d



On Oct 24, Roland Rosenfeld wrote:
> 
> > for i in /etc/profile.d/*.sh; do
> >     . $i
> > done  
> 
> But there are shells (for example csh and tcsh) which doesn't support
> this syntax of "for".  So your proposal isn't acceptable.
> 
> > Of course, Debian Policy tells 
> 
> > "No program may depend on environment variables to get reasonable
> > defaults. (That's because these environment variables would have to be
> > set in a system-wide configuration file like /etc/profile, which is
> > not supported by all shells.)"
> 
> So if you know that the policy forbids profile.d, why do you start
> this discussion here?  If you want to change the policy, debian-policy
> is the correct mailing list (but there you should be prepared better
> than simply telling us, that the above for loop solves all problems),
> you should especially provide a solution for _all_ available login
> shells.

I don't know if anyone's already brought this up before, but there's a
fair bit you can do in relatively shell-independant code.  If you're
willing to depend on eval, ||, &&, backticks, goto, and so forth.

I worked on a generic shell configuration system here at McGill at one
point, but there didn't seem to be enough interest to pursue it too far.
Basically, it used lowest-common denominator commands to implement at
least macros (i.e. aliases without parameters) and environment variables
generically.  Won't work for any conceivable shell, and in fact I only
aimed for compatibility with the csh- and sh- derived shells.  But it
may be sufficient for what the original poster wanted.  No for loops,
mind you, but you could do something like:

  # could use whichshell (from bsh@iname.com) instead if you wanted to
  # be more thorough; this would probably break on zsh, for example.
  [ `expr "$0" : '[^c]*csh'` -gt 0 ] || eval <<EOE
  source () {
  .
  } 
  SHELLTYPE=sh
  export SHELLTYPE
  EOE

  [ "$SHELLTYPE" = sh ] || setenv SHELLTYPE csh

  source `cat /etc/profile.d/*`

(assuming all files in /etc/profile.d were written similarly genericly.)
'Course, it's ugly as sin...


Reply to: