Subject: Re: a shell idea?
To: None <roskens@cs.umn.edu>
From: 51482) <etorwi@etn.ericsson.se (Raymond A. Wiker>
List: current-users
Date: 10/10/1995 09:57:25
Ron Roskens writes:
 > Simon J. Gerraty writes:
 > > >   ``Add this directory iff it's not already in the path''
 > > 
 > > Very useful.  My /etc/profile has had an add_path() function for
 > > years.  It does not check for the directory being in PATH because in
 > > /etc/profile you _know_... the add_path() and friends used in
 > > /etc/ksh.kshrc though do test for presence in PATH.
 > 
 > There exists package called Modules. It does what your asking but in a
 > different manner than your approaching it. The idea behind Modules was that
 > from a sysadmin's standpoint, having a set of configuration files available
 > for users to "source" makes the setup of new paths easier to maintain.

	Interesting... this seems similar to what we are using at Ericsson
Norway - our startup profiles are based around the aliases

eto_prepend VAR value 
eto_append VAR value
eto_require PACKAGE

--- although our system uses a hierarchy of startup files,
corresponding to the structure of our organisation (as an example, a
SW engineer in the department X/D/F sources startup files for X, X/D
and X/D/F in addition to his (her) personal setup.

	One of the main advantages of using the set of
aliases/functions listed above, is that the startup files for many
applications can be written purely in terms of them. That again means
that the startup files are independent of the shell used.

	The definitions we're using (which I see are a bit
Sun-centric; must remember to fix that later) are:

csh/tcsh: 
--------------------------------------------------------- 
if ( `uname -r` =~ 5.* ) then
   set test='/usr/ucb/test'
   set hostname='/usr/ucb/hostname'
else
   set test='/usr/bin/test'
   set hostname='/usr/bin/hostname'
endif
 
alias eto_append    'eval $test "1 = $?\!:1" && setenv \!:1 "${\!:1}:\!:2" || setenv \!:1 "\!:2"'
alias eto_prepend   'eval $test "1 = $?\!:1" && setenv \!:1 "\!:2":"${\!:1}" || setenv \!:1 "\!:2"'
alias eto_require   'eval "if (("${FEATURES}" !~ *:"\!:1":*) && ( -r \!:1/.cshrc )) then \\
   setenv FEATURES ${FEATURES}"\!:1": \\
   source \!:1/.cshrc \\
endif"'
---------------------------------------------------------
 
bash:
---------------------------------------------------------
setenv() {
        eval $1=\'$2\'; export $1
}
 
eto_append() {
        eval $1='${'$1':+${'$1'}":"}'\'$2\'; export $1
}
eto_prepend() {
        eval $1=\'$2\''${'$1':+":"${'$1'}}'; export $1
}
 
eto_featurep() {
        echo ":${FEATURES}:" | fgrep ":"$1":" > /dev/null 2>&1 
}
 
eto_require() {
        if
                eto_featurep $1
        then
                :
        elif
                test -r $1/.shrc
        then
                eto_append FEATURES $1
                . $1/.shrc
                :
        fi
}
--------------------------------------------------------- 

	Anyone who still doubts that csh is ill-suited for scripting
should make a thorough comparison of the two sets of defintions above ;-)

	//Raymond.