------------------------------------------------------------------------------- Default Environment Set by Shells... Find out what environment a shell defines by default... env - {shell} -c '/usr/bin/env' Sh: ---no extra environment defines--- Ksh: PWD _ Csh: PWD USER Tcsh: PWD USER SHLVL LOGNAME GROUP VENDOR REMOTEHOST HOST HOSTTYPE OSTYPE MACHTYPE Zsh: PWD HOME LOGNAME SHLVL OLDPWD _ Bash: PWD SHELL SHLVL HOSTNAME MACHTYPE OSTYPE OLDPWD _ ------------------------------------------------------------------------------- Environment handling by shells Bourne shell just marks variables as being exported or not exported. Changing an exported variable also changes the value being exported. However if you change a variable that has NOT been marked for export IN THAT SHELL, a local copy is maintained and used and the change is not exported (the original export variable is). The 'set' command only lists variables that have been 'set' within the current shell, not the imported environment variables. IE it will show a changed environment variable. Csh maintains two completely separate lists of variables for local and environmental purposes. The local variable list overrides the environmental when there is a clash. A few variables (like path) are linked to their environmental counterparts (ie, PATH). ------------------------------------------------------------------------------- Inherited functions... See "functions.txt" and "shell_shock.txt" ------------------------------------------------------------------------------- Listing Variables set # lists all variables and functions env # exported environment variables bash -c 'set -o posix; set' # lists non-exported environment typeset # lists non exported environment variables and functions # in a form that can be executed by the shell # (builtin inherited from zsh) typeset -a # list arrays (as shell definitions typeset -A # list associative arrays typeset -f # functions typeset -x # exported typeset -p | grep -a '^declare -- ' # unexported settings ........ Seperate "env" output better (as it can be multi-line!) env -0 | perl -0pe 's/\0$/\n---\n/g' Grep with multi-line handling... env -0 | grep -z ^BASH_FUNC | tr '\0' '\012' env -0 | grep -z ^BASH_FUNC | perl -0pe 's/\0$/\n#---\n/' ------------------------------------------------------------------------------- Add a PATH component (before or after) (can be used for MANPATH or LD_LIBRARY_PATH too) # function: addpath {bin_path} ['after'] addpath () { case ":${PATH}:" in *:"$1":*) : path component present - abort ;; *) if [ "$2" = "after" ]; then PATH="$PATH:$1" else PATH="$1:$PATH" fi esac } Remove PATH component (bash) LD_LIBRARY_PATH=`echo "$LD_LIBRARY_PATH" | sed 's|/opt/SUNWdxlib/[^:]*||g; s|:::*|:|g; s|^:||; s|:$||;'` export LD_LIBRARY_PATH echo "LD_LIBRARY_PATH = $LD_LIBRARY_PATH" -------------------------------------------------------------------------------