Help! Crushed by shells

Help! Crushed by shells

Post by Christopher C. Eve » Fri, 25 Aug 1995 04:00:00



: I hope this is not a FAQ. But I am faced with a user community using a myraid
: of shells and I must pander to them all. Here is one problem I have. I have
: to set certain environment variables across all shells. I need to create an

If the SHELL environment variable is set for everyone, you could have
two shell scripts.  The first one, which the users source (or .) would
have something like:

exec /bin/csh -f <your second file>

Then in your second file, have csh commands doing what you want, followed
by:

exec $SHELL

Except for the fact that people's rc files might be run again, this ought
to do it.

Hope this helps,
Chris "eval `perl -e 'print ($ENV{"SHELL"} =~ /csh/? qq-setenv XXX val\n-: qq-XXX=val\n;export XXX-;'" Evert
--
Christopher C. Evert            Opinions are mine, not Western Geophysical's.

uunet!airgun!cevert             Gnostically Uncanny Rhizuser of UNIX

 
 
 

Help! Crushed by shells

Post by Soren Dayt » Fri, 25 Aug 1995 04:00:00





>: I hope this is not a FAQ. But I am faced with a user community using a myraid
>: of shells and I must pander to them all. Here is one problem I have. I have
>: to set certain environment variables across all shells. I need to create an

        You could do something relatively silly:

                have an awk (or some other) script that spits out the
                correct syntax based on the contents of the SHELL
                variable:

                        `set-environment`

        This wouldn't be _that_ repulsive, but it _does_ require an
        external program.

Soren

 
 
 

Help! Crushed by shells

Post by Ravi Kum » Fri, 25 Aug 1995 04:00:00


I hope this is not a FAQ. But I am faced with a user community using a myraid
of shells and I must pander to them all. Here is one problem I have. I have
to set certain environment variables across all shells. I need to create an
include file, which can be sourced from any shell. In other words I want
something like this.

if (shell == csh || shell == tcsh )
  setenv TESTPATH=/user/ravi/misc/tests
else if (shell == bash || shell == ksh || shell == sh )
  TESTPATH=/user/ravi/misc/tests
  export TESTPATH

How do I accomplish this?

--
Cheers,
Ravi Kumar   :    Endangered Near Extinct Species, Texas Instruments. Dallas.
Due to a shortage of devoted followers, the production of great leaders has
been discontinued. And all opinions are mine. Great leaders are like that.

 
 
 

Help! Crushed by shells

Post by Ravi Kum » Sat, 26 Aug 1995 04:00:00


OK,

        Looks like I confused the hell out of everyone. Sorry. Here is what
I need. A single file with stuff in it.  This file should set, say the
environment variable PATH (just to impress upon you that you cannot make
*any* assumptions on the shell).

        The real deal is that we will need to maintain up to a hundred
interdependant environment variables (no kidding). I just cant maintain two
files.

        How do I do this? My boss had this idea.

/bin/test "$shell" || exec bash -c "exec path_setup; exec $shell"
/bin/test "$shell" && . path_setup

How does this work? In both csh and tcsh there exists this $shell variable
So if it doesn't it is not a csh shell family. (What if some one has a $shell
defined in his bash :-) Tough beans ).

        It works because test is found in /bin/test on all our platforms. It
works because bash is in everyone's path. It is a terrible kludge.  So can
someone  please help me here.

--
Cheers,
Ravi Kumar   :    Endangered Near Extinct Species, Texas Instruments. Dallas.
Due to a shortage of devoted followers, the production of great leaders has
been discontinued. And all opinions are mine. Great leaders are like that.

 
 
 

Help! Crushed by shells

Post by Daniel Egn » Sat, 26 Aug 1995 04:00:00




>    You could do something relatively silly:

>            have an awk (or some other) script that spits out the
>            correct syntax based on the contents of the SHELL
>            variable:

>                    `set-environment`

>    This wouldn't be _that_ repulsive, but it _does_ require an
>    external program.

Yeah, but in csh, you can't have "set-environment" output something
containing a backquote (useful if you want to define aliases as well
as env vars...)

  set-environment > /tmp/blah.$$
  source /tmp/blah.$$
  rm /tmp/blah.$$

<puke>, Dan

 
 
 

Help! Crushed by shells

Post by Soren Dayt » Sat, 26 Aug 1995 04:00:00






>>        You could do something relatively silly:

>>                        `set-environment`
>Yeah, but in csh, you can't have "set-environment" output something
>containing a backquote (useful if you want to define aliases as well
>as env vars...)
>  set-environment > /tmp/blah.$$
>  source /tmp/blah.$$
>  rm /tmp/blah.$$

        Actually, you would probably want so solve it by having
        set-environment write to a file and then spit out:

                source somefile ; rm somefile

        :)

        But this is all ridiculous, as I stated above.  Assuming that
        all you were doing is setting variables and possibly aliases,
        how hard would it be to write a series of aliases and
        functions in (ba|k)sh to do this?  Things like:

        setenv () {
                $1="$2"
                export $1
        }

        alias () {
                eval "builtin alias $1=\"$2\""
        }

                Note that this is needed because of when the alias is
                aliased ( I think, someone please check me on this ).

        Exploit the fact that things like PATH and path are set in
        synch.  and possibly even try some other tricks like that.  Is
        there a good way to get rid of functions?  I cannot find one
        in the manpage (zsh's unfunction is nice.  es's ( fn-$name = )
        is better, but nothing analogous )

        Of course this is still ugly, but it might be closer to
        addressign the problem without doing somthing like the:

                /bin/test -n "$shell" && ....
                /bin/test -n "$shell" ||

                mess.

Soren

 
 
 

Help! Crushed by shells

Post by sq » Wed, 06 Sep 1995 04:00:00



> ...  Here is what
>I need. A single file with stuff in it.  This file should set, say the
>environment variable PATH (just to impress upon you that you cannot make
>*any* assumptions on the shell).
> ...

If you just want to set variables, why don't you have a master file
containing a list of name-value pairs and transfer that automatically
into the respective notions of the shells you need to support ?

You could start with a plain file, each line contains a name and a string
(the string possibly containing references to variables already set).

For the C shell family, you would copy that and set 'setenv' in front of
each line.
For the Bourne shell, you would replace the blanks between by an equals sign
and add 'export ...' at the end.
Depending on your needs, you might add quoting (for strings containing ';')
or require that to be in the master file.

If you need more (control structures etc.), you might insert these in the variants
needed and use conditional compiling to extract the variant of 'if' you need.

In any case, you would maintain only one file and extract the variants automatically.

Any requirement I missed ?

Joerg Bruehe, SQL Datenbanksysteme, Berlin (Germany)
--