packages icon



 ENVV(1)                                                             ENVV(1)
                                18 April 1994



 NAME
      envv - manipulate environment variables in shell-independent manner

 SYNOPSIS
      envv [options] set env_var value

      envv [options] local env_var value

      envv [options] add path_var dir [pos]

      envv [options] move path_var dir pos

      envv [options] del path_var dir

      envv [options] choose sh_val csh_val

      envv [options]

 OPTIONS
      -e   Do not escape shell meta-characters when issuing commands

      -s   Issue a semicolon after each command

      -h   Display usage information

 DESCRIPTION
      Envv is used to manipulate environment variables in a shell-
      independent manner.  It is most useful in administrator-maintained
      setup files for various software packages.

      Envv accepts directives, either on the command line or from standard
      input, and issues shell commands tailored to the user's shell.

      For example, on our system, each software package has a setup script
      in a fixed directory (/usr/share/setup) which sets up environment
      variables and adds directories to the users' PATH as required by the
      package.  The scripts to do this are slightly different for csh-like
      shells (csh, tcsh) and sh-like shells (sh, ksh, bash.)  Envv
      eliminates the need for two separate scripts.

      Envv examines the SHELL environment variable for the name of a shell
      which it recognizes.  If that doesn't work, it uses information from
      the passwd file to find the user's shell.  It then issues commands
      appropriate for the shell to standard output.  Here's a simple
      example:

           eval `envv set NAME David`

      If your shell is csh, then envv emits "setenv NAME David" to standard
      output.  If your shell is sh, the it emits "NAME=David; export NAME"
      to standard output.  Either way, the environment variable is set



                                    - 1 -         Formatted:  April 19, 2024






 ENVV(1)                                                             ENVV(1)
                                18 April 1994



      correctly.

 SET
      The simplest directive is the set command, illustrated above.  Note
      that shell characters are normally escaped, so that:

           envv set NAME 'David* F. Skoll'

      will emit "setenv NAME David\*\ F.\ Skoll" under csh.  However, if the
      -e option is supplied, then Envv will emit "setenv NAME David* F.
      Skoll", with all the difficulties that may imply.

 LOCAL
      Local is similar to set, except that it does not export the variable
      to the environment.  Thus:

           envv local name David

      will emit "set name=David" in csh, and "name=David" in sh or bash.

 ADD
      The add directive adds the specified directory to a colon-separated
      path list, if the directory is not already present.  If pos is
      supplied, the new directory is placed at the specified position, which
      are numbered starting with 1.  If pos is not specified, or is out-of-
      range, the new directory is added at the end.

      For example, suppose that under csh, your PATH is /bin:/usr/bin.
      Then:

           envv add PATH /foo     yields "setenv PATH /bin:/usr/bin:/foo"
           envv add PATH /foo 1   yields "setenv PATH /foo:/bin:/usr/bin"
           envv add PATH /foo 2   yields "setenv PATH /bin:/foo:/usr/bin"
           envv add PATH /bin     yields nothing - /bin already on path
           envv add PATH /bin 2   yields "setenv PATH /usr/bin:/bin"

      The last example shows that an 'add' is converted to a 'move' if the
      directory is already on the path, and a position is supplied.  Of
      course, to have any effect, all of the above examples would be used in
      an eval `...` structure.

 DEL
      The del command deletes a directory from the path variable.  Suppose
      that MANPATH is set to /man:/usr/man, and that your shell is bash.
      Then:

           envv del MANPATH /man     yields "MANPATH=/usr/man; export MANPATH"
           envv del MANPATH /usr/man yields "MANPATH=/man; export MANPATH"
           envv del MANPATH /foo     yields nothing





                                    - 2 -         Formatted:  April 19, 2024






 ENVV(1)                                                             ENVV(1)
                                18 April 1994



 MOVE
      The move command moves a directory in the path to the specified
      position.  Suppose you're running tcsh, and the environment variable P
      is set to a:b:c:d.  Then:

           envv move P a 2         yields "setenv P b:a:c:d"
           envv move P a 999       yields "setenv P b:c:d:a"
           envv move P d 1         yields "setenv P d:a:b:c"
           envv move P e 1         yields nothing - e is not on path.

 CHOOSE
      The choose command is very simple:  It takes two arguments.  If the
      user's shell is like sh, then the first argument is printed.  If it is
      like csh, then the second argument is printed.

      This is useful if commercial vendors have supplied two versions of
      scripts which must be sourced.  Your system script can select the
      proper script as follows:

           source `envv choose script.sh script.csh`

      This can also be used as an escape hatch for complicated tests which
      really do require two separate shell scripts.

 SUPPLYING DIRECTIVES ON STANDARD INPUT
      If no directives are given on the command line, then envv reads
      standard input for directives, which should be supplied one-per-line.
      Envv processes all of the directives until end-of-file is encountered.
      For example, you could do something like this:

           envv << 'END_OF_STUFF' > /tmp/env.$$
           set A 1
           set B 2
           add PATH /bin/foo
           'END_OF_STUFF'
           source /tmp/env.$$
           rm /tmp/env.$$

      This creates a temporary shell script which holds the commands to set
      A and B, and add /bin/foo to the path.  This temporary script is then
      sourced and deleted.  If you have many variables to set, this may be
      faster and/or easier to maintain than multiple envv commands.

      When envv reads from standard input, it uses whitespace characters to
      separate directives from their arguments, and the arguments from each
      other.  If you want to include whitespace in an argument, escape it
      with a backslash.  No other characters need be escaped.  For example,
      if you want to set the environment variable NAME to "David Skoll", use
      this in the input to envv:





                                    - 3 -         Formatted:  April 19, 2024






 ENVV(1)                                                             ENVV(1)
                                18 April 1994



           set NAME David\ Skoll

 NOTES
      The path-manipulation directives (add, move, del) ignore trailing
      slashes when comparing path components.  Thus, "/usr/local" and
      "/usr/local/" are considered the same.  When components are added or
      moved in a path variable, they inherit whatever slashes are supplied
      in the dir argument.  Experiment...

      The path-manipulation commands can add, move or delete only one
      directory at a time.  For example, use this:

                add PATH /foo
                add PATH /bar

      and not this:

                add PATH /foo:/bar

 AUTHOR
      Envv is Copyright 1994 by David F. Skoll.  It may be distributed for
      free.  The only fees which may be charged are normal media costs or
      BBS access fees.  Envv may not be distributed as part of a commercial
      package.  Other fees, such as support fees, consulting fees, or
      special higher-than-normal BBS access fees may not be charged.

 BUGS
      If you have multiple add, del or move commands in a standard-input
      command list, they emit multiple shell commands to set the path
      variable.  It would be nicer if only one command which reflected the
      final result were emitted.























                                    - 4 -         Formatted:  April 19, 2024