[ Team LiB ] |
Tasks Common to All ShellsThe following sections describe concepts and tasks that can be used with any shell. Setting a Default Shell
Changing Shells from a Command Line (csh, ksh, sh, bash, tcsh)If you want to use another shell without modifying the Passwd database, you can change shells at a command-line prompt by simply typing the name of the shell you want to use. To change to the C shell, type csh and press Return. The default C shell prompt is the system name followed by a percent sign (%).
$ csh
paperbark%
To change to the Korn shell, type ksh and press Return. The default Korn shell prompt is a dollar sign ($).
paperbark% ksh
$
To change to the Bourne shell, type sh and press Return. The default Bourne shell prompt also is a dollar sign ($).
$ sh
$
paperbark% bash
bash-2.03$
To change to tcsh, type tcsh and press Return. The default tcsh prompt is >.
paperbark% tcsh
>
To change to the Z shell, type zsh and press Return. With no startup files, the prompt does not change. Quitting from a Shell (exit)If you start a new shell from the command line, you can quit it and return to the old shell. To quit from a shell, type exit and press Return. If you have started (layered) another shell, you are returned to the original shell prompt.
$ exit
oak%
Setting Aliases, Paths, and Environment VariablesEnvironment variables in a shell are inherited by all subsequent shells and any programs you start from them. For shells that have two login files—all but the Bourne shell—you should set all environment variables in the .login file. Aliases and functions are not inherited by subsequent shells. They are redefined for each shell separately. Set aliases and functions in the .cshrc file for the C shell, in the . ksh_env file for the Korn shell, and in the relevant files for tcsh, bash, and zsh shells. The following example shows what can go wrong if you don't follow the guidelines about where to set environment variables. Using the C shell as an example, suppose you know your login C shell sources $HOME/.cshrc whenever you start a shell—call this Shell1. Now, you add the following command to the PATH variable in $HOME/.cshrc. setenv PATH ${PATH}:/my/dir If you now start another shell from Shell1, that shell inherits the PATH setting from Shell1 (because it's an environment setting), but your $HOME/.cshrc file gets sourced again, thus adding : ...:/my/dir:/my/dir .to the end of your PATH. Not good. This construct can, over time, overflow your PATH environment variable, resulting in an administrative nightmare. However, when you use $HOME/.login as the place to set the PATH environment variable, your login shell gets the definition of PATH and all subsequent shells inherit it.
NOTE. You must export environment variables for the Bourne, Korn, Bourne-Again, and Z shells so that their children can inherit them. The Solaris Operating Environment provides several default environment variables.
CAUTION. Including . in the path to search the current directory is a potential security problem. If security is an issue at your site, do not include . as part of a user's path. Never use . as part of the root path.
Other environment variables include the following.
Users and system administrators can define additional variables for their own use. When you define an environment variable from a shell command, the variable remains in effect while you are working in the shell. When you exit the shell, the environment variable is not retained. Store "permanent" environment variables that are likely to be used during each login session in the .profile or .login file. The syntax for defining environment variables depends on the shell and is described elsewhere in this chapter. Setting the Path for Bourne and Korn ShellsThe path for the Bourne and Korn shells is specified in the user's $HOME/.profile file as shown in the following example. PATH=/usr/bin:/$HOME/bin:. Setting the Path for the C ShellThe path for the C shell is specified in the user's $HOME/.cshrc file (with the set path environment variable) as shown in the following example. set path = (/usr/bin $home/bin .) See the appropriate manual pages for an in-depth description of these commands, and also see Chapter 12, "Recognizing File Access Problems," for more information about troubleshooting problems with paths. Displaying Environment Variable Settings (env)Each shell maintains an environment with a set of specifications that it gets from the user's initialization files (.profile for the Bourne and Korn shells or .cshrc and .login for the C shell) or from environment variables set interactively from a shell. These environment variables can specify information such as the user's home directory, login name, default printer, location for e-mail messages, and path for accessing the OpenWindows environment. To display a list of the current environment variable settings, type env and press Return. The following example shows all the environment variables for a system running CDE.
paperbark% env
MANPATH=/usr/dt/man:/usr/man:/usr/openwin/share/man
DTDATABASESEARCHPATH=/export/home/winsor/.dt/types,/etc/dt/appconfig/types/%L,
/etc/dt/appconfig/types/C,/usr/dt/appconfig/types/%L,/usr/dt/appconfig/types
/C
DTXSERVERLOCATION=local
LANG=C
HELPPATH=/usr/openwin/lib/locale:/usr/openwin/lib/help
DTSOURCEPROFILE=true
PATH=/usr/openwin/bin:/usr/dt/bin:/export/home/opt/SUNWadm/bin:/bin:/usr/bin:/
usr/sbin:/usr/ucb:/etc:/usr/proc/bin:/usr/ccs/bin:/opt/hpnp/bin:/opt/NSCPcom
:/usr/local/games:.
AB_CARDCATALOG=/usr/dt/share/answerbooks/C/ab_cardcatalog
DTUSERSESSION=winsor-paperbark-0
XMICONBMSEARCHPATH=/export/home/winsor/.dt/icons/%B%M.bm:/export/home/winsor/.
dt/icons/%B%M.pm:/export/home/winsor/.dt/icons/%B:/etc/dt/appconfig/icons/%L
/%B%M.bm:/etc/dt/appconfig/icons/%L/%B%M.pm:/etc/dt/appconfig/icons/%L/%B:/e
tc/dt/appconfig/icons/C/%B%M.bm:/etc/dt/appconfig/icons/C/%B%M.pm:/etc/dt/ap
pconfig/icons/C/%B:/usr/dt/appconfig/icons/%L/%B%M.bm:/usr/dt/appconfig/icon
s/%L/%B%M.pm:/usr/dt/appconfig/icons/%L/%B:/usr/dt/appconfig/icons/C/%B%M.bm
:/usr/dt/appconfig/icons/C/%B%M.pm:/usr/dt/appconfig/icons/C/%B
SESSION_SVR=paperbark
OPENWINHOME=/usr/openwin
EDITOR=/usr/dt/bin/dtpad
LOGNAME=winsor
DTSCREENSAVERLIST=StartDtscreenSwarm StartDtscreenQix StartDtscreenFlame
StartDtscreenHop StartDtscreenImage StartDtscreenLife StartDtscreenRotor
StartDtscreenPyro StartDtscreenWorm StartDtscreenBlank
MAIL=/var/mail/winsor
USER=winsor
DISPLAY=:0.0
SHELL=/bin/csh
DTAPPSEARCHPATH=/export/home/winsor/.dt/appmanager:/etc/dt/appconfig/appmanage
r/%L:/etc/dt/appconfig/appmanager/C:/usr/dt/appconfig/appmanager/%L:/usr/dt/
appconfig/appmanager/C
HOME=/export/home/winsor
XFILESEARCHPATH=/usr/openwin/lib/locale/%L/%T/%N%S:/usr/openwin/lib/%T/%N%S
XMICONSEARCHPATH=/export/home/winsor/.dt/icons/%B%M.pm:/export/home/winsor/.dt
/icons/%B%M.bm:/export/home/winsor/.dt/icons/%B:/etc/dt/appconfig/icons/%L/%
B%M.pm:/etc/dt/appconfig/icons/%L/%B%M.bm:/etc/dt/appconfig/icons/%L/%B:/etc
/dt/appconfig/icons/C/%B%M.pm:/etc/dt/appconfig/icons/C/%B%M.bm:/etc/dt/appc
onfig/icons/C/%B:/usr/dt/appconfig/icons/%L/%B%M.pm:/usr/dt/appconfig/icons/
%L/%B%M.bm:/usr/dt/appconfig/icons/%L/%B:/usr/dt/appconfig/icons/C/%B%M.pm:/
usr/dt/appconfig/icons/C/%B%M.bm:/usr/dt/appconfig/icons/C/%B
TERM=dtterm
dtstart_sessionlogfile=/dev/null
TZ=Australia/West
DTHELPSEARCHPATH=/export/home/winsor/.dt/help/winsor-paperbark-0/%H:/export/ho
me/winsor/.dt/help/winsor-paperbark-0/%H.sdl:/export/home/winsor/.dt/help/wi
nsor-paperbark-0/%H.hv:/export/home/winsor/.dt/help/%H:/export/home/winsor/.
dt/help/%H.sdl:/export/home/winsor/.dt/help/%H.hv:/etc/dt/appconfig/help/%L/
%H:/etc/dt/appconfig/help/%L/%H.sdl:/etc/dt/appconfig/help/%L/%H.hv:/usr/dt/
appconfig/help/%L/%H:/usr/dt/appconfig/help/%L/%H.sdl:/usr/dt/appconfig/help
/%L/%H.hv:/usr/dt/appconfig/help/C/%H:/usr/dt/appconfig/help/C/%H.sdl:/usr/d
t/appconfig/help/C/%H.hv
XMBINDDIR=/usr/dt/lib/bindings
WINDOWID=96469001
TERMINAL_EMULATOR=dtterm
PWD=/export/home/winsor
paperbark%
Clearing a Shell Window (clear)You can clear the contents of a shell window and redisplay the prompt at the top of the window. To clear the contents of a shell window, type clear and press Return. oak% ls -l /home/ignatz/quest -rw-r--r-- 1 ignatz staff 24 Jul 16 15:07 quest oak% clear The window is cleared and the prompt is redisplayed at the top. Setting the Shell Backspace Key (stty erase)If you want to change the erase key from Delete to Backspace, type stty erase, then press Control and Shift together, and then type H and press Return. The Backspace key is set as the erase key. The following example changes the erase key for the C shell.
oak% stty erase ^H
oak%
Typing Several Commands on the Same Command Line (;)You can type more than one command on a single command line by typing a semicolon (;) between the commands. For example, you can change to a directory and list the commands by typing cd /usr/bin;ls and pressing Return. The following example sets an environment variable for the Bourne shell and then exports the variable.
$ PATH=/usr/bin:$HOME/bin:.;export PATH
$
Redirecting Output (<>)Unless you indicate otherwise, commands normally display their results on the screen. You can, however, redirect the output of a command by using the redirect symbols < and >. For example, to save the output to a file instead of displaying it on the screen, use the > redirect symbol to tell the shell to put the contents into a file. In the following example, the output of the date command is redirected to a new file called date.file.
$ date > date.file
$
The following example shows the contents of date.file.
paperbark% more date.file
Wed May 3 15:59:50 WST 2000
paperbark%
You can also redirect input in the other direction. For example, to mail the contents of a file to user ignatz@oak, type mail ignatz@oak < report.file and press Return. The file called report.file is sent by e-mail to ignatz@oak. Combining Commands (|)You can use the pipe (|) operator to connect two or more commands, using the output from one command as the input to the next one. This section provides two examples of the many ways you can combine commands in a pipeline. To print the cat(1) manual page, type man cat | lp and press Return. The manual page is not displayed on the screen. Instead, the output is sent to the lp command, which prints it on the default printer. You can search the process list for a particular command by piping the output of ps -e to the grep command. The output is displayed on the screen. The following example displays process information for OpenWindows.
cinderella% ps -e | grep openwin
260 ? 0:00 openwin
cinderella%
If you want to print the information, you can add an additional pipe command (| lp) to the end of the sequence and send it to the printer, as shown in the following example.
anastasia% ps -e | grep openwin | lp
request id is castle-51 (request id is castle-51 (standard input)
anastasia%
|
[ Team LiB ] |