mks_env delete name
The mks_env utility is an MKS KornShell built-in that lets you save and restore shell environments using the registry. It has five sub-commands: load, save, delete, list, and script.
The save sub-command saves the environment with the
This name identifies the registry key in which the environment information
is stored. With the
The following variables are explicitly not saved by the save sub-command:
ARGS HISTCMD LINENO LINENO LOGONSERVER MKS_ENV_LOAD_NAME NUMBER_OF_PROCESSORS PPID PROCESSOR_ARCHITECTURE PROCESSOR_IDENTIFIER PROCESSOR_LEVEL PROCESSOR_REVISION PWD SECONDS SHELL_VERSION SystemDrive SystemRoot USERDOMAIN USERNAME USERPROFILE windir
The load sub-command loads a named environment. When the load sub-command specifies a name argument, the environment variable MKS_ENV_LOAD_NAME is set to name. This lets you use that same name to re-save the environment with that same name. For example, the following script autosaves the environment every 10 commands:
mks_env load ENVNAME # loads environment ENVNAME trap 'if [ $((HISTCMD%10)) == 0 ] ; then mks_env save "$MKS_ENV_LOAD_NAME" ; fi' DEBUG mks_env save ENVNAME # saves environment ENVNAME with autosave DEBUG # trap added
You can also use the sh
The delete sub-command deletes the saved environment with the specified name.
The list sub-command displays one or more of the names, time stamps, and registry paths of saved environments. When no options are specified with list, just the names of the saved environments specified by the name arguments (or all saved environments if no name arguments are given).
The script sub-command generates a script that, when sourced (with the . or source utility), recreates the current environment. This generated script is written to standard output.
With a combination of various sub-commands, the trap
utility and the sh
deletes the specified key after loading it.
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 nologwas 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
when used with the list sub-command, displays the registry paths for the specified saved environments.
when used with the save sub-command, 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
when used with the list sub-command, displays the names and time stamps for the specified saved environments.
when used with the list sub-command, displays the names, time stamps, and registry paths for the specified saved environments.
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.
To dump the contents of the saved environment named saved_env:
registry -p -k "$(mks_env list -r name)"
Possible exit status values are:
Windows 7. Windows Server 2008 R2. Windows 8. Windows Server 2012. Windows 10. Windows Server 2016.
mks_env is an MKS extension.
PTC MKS Toolkit for Power Users
PTC MKS Toolkit for System Administrators
PTC MKS Toolkit for Developers
PTC MKS Toolkit for Interoperability
PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition
PTC MKS Toolkit 10.1 patch 1 Documentation Build 2.