mks_env

save, restore, and delete shell environments 

KornShell Built-in


SYNOPSIS

mks_env load [-d] [-kenv_piece] name

mks_env save [-kenv_piece] [-r shellcmd] [name]

mks_env delete name


DESCRIPTION

The mks_env utility is an MKS KornShell built-in that lets you save and restore shell environments using the registry. It has three sub-commands: load, save, and delete which let you load, save, and delete named shell environments. You can also use the sh -R option to load a saved environment.

The name argument specifies the name of a saved environment. This name identifies the registry key in which the environment information is stored. With the save sub-command, name is optional. When it is not specified, mks_env generates a unique name and saves the environment with that name.

With a combination of the three sub-commands, the trap utility and the sh -R option, you can configure your shell to save the environment when you exit and then load that environment when you enter the shell again. You can also use these features to create specific shell environments that can be loaded on demand. This can be handy for development and quality assurance purposes.

Options

-d 

deletes the specified key after loading it. This option is only available with the load sub-command.

-kenv_piece 

specifies which piece of the environment is to be saved or loaded. env_piece is a string of one or more of the following characters:

P    Position. This is all stty info,
including position
     and buffer size, but not including font information
S    Symbol Table. This includes aliases and functions. However, functions
     are only remembered if set -o nolog was not on when
     the function was defined.
T    Traps. This includes all user-defined traps.
V    Variables. This includes all environment variables, all set options,
     and the current directory.
-r shellcmd 

specifies a shell command to be written to the HKEY_CURRENT_USER/Software\Mortice Kern Systems\Toolkit\Shell\Environments\RunOnce key. mks_env prepends wstart -D desktop -c to specified command, replacing desktop with the name of desktop in which the shell is running.

This option is particularly handy for LOGOFF traps where only shell built-ins can be run. For example:

trap 'mks_env save -r "$SHELL -R $$,SVPT,d" $$' logoff


EXAMPLES

To restore every shell and environment that you had at logout, place the following command in your profile.ksh file:

trap 'mks_env save -r "$SHELL -R $$,SVPT,d" $$" logoff

To automatically create a file that can be used to restore an environment in the case of an accidental or error-caused exit from the shell, place the following two commands in your profile.ksh file.

trap "if [ \$(( HISTCMD%10 )) == 0 ] ;then mks_env save sh_env_$$ ; fi" DEBUG
trap "mks_env delete sh_env_$$ " CLOSE EXIT LOGOFF

The first command saves your environment every 10 commands. The second command deletes the automatically saved environment upon a normal exit from the shell.

To have a certain startup at every login, get everything setup the way you like and run the following commands:

SHELL_ENV_NAME="some_unique_name"
mks_env save "$SHELL_ENV_NAME"
registry -k 'HKEY_CURRENT_USER/SoftWare/Microsoft/Windows/CurrentVersion/Run" \
    -n "$SHELL_ENV_NAME" -v'wstart -D $(desktop) -c $SHELL -R "$SHELL_ENV_NAME"'

Once you have save a few different environments, you can make a desktop shortcut pointing at:

sh -R name

For example, you might create on shortcut for the local development environment and another shortcut for a remote development environment.


DIAGNOSTICS

Possible exit status values are:

0 

Successful completion.

>0 

An error occurred.


PORTABILITY

Windows 2000. Windows XP. Windows Server 2003. Windows Vista.

mks_env is an MKS extension.


AVAILABILITY

MKS Toolkit for Power Users
MKS Toolkit for System Administrators
MKS Toolkit for Developers
MKS Toolkit for Interoperability
MKS Toolkit for Professional Developers
MKS Toolkit for Enterprise Developers
MKS Toolkit for Enterprise Developers 64-Bit Edition


SEE ALSO

Commands:
set, sh, trap


MKS Toolkit 9.2 Documentation Build 16.