Shell features
1 / 27

Shell Features - PowerPoint PPT Presentation

  • Updated On :

Shell Features. Chapter 14. Overview. Bourne Shell ($) – Original shell for UNIX environment developed for AT&T V.2. Does not support alias, history or command line editing and is used primarily by system admins.

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about 'Shell Features' - johana

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Shell features

Shell Features

Chapter 14


  • Bourne Shell ($) – Original shell for UNIX environment developed for AT&T V.2. Does not support alias, history or command line editing and is used primarily by system admins.

  • Korn Shell ($)- Superset of the Bourne. Supports aliasing, history and command line editing. Most widely used.

  • C shell (%) – Based on C programming language. Supports aliasing and history.

  • BASH – Bourne-Again Shell ($) – has the feel of the Bourne and Korn and incorporates the C and Korn.


  • The Korn shell is the default shell for Solaris users and the Bash shell is the default for Linux users.

  • The shell accepts commands issued by the user, interprets these commands, and executes the appropriate programs.

  • Shells can be command line or graphical, and are also interchangeable.

  • Several of the shell features include:

    • Wildcard matching

    • Input/output redirection.

    • Pipes

    • Background processing

    • Programming language features are used to create shell scripts that perform complex operations.

Understanding the shell
Understanding the Shell

  • The shell is only loaded when a user logs in at a text-mode login or launches a shell

  • Shell is like any other program running on Linux. It has no special privileges.

  • init program displays a login prompt, but doesn’t load the shell.

  • Graphical users are limited to what is available on the menu.

  • Shell’s primary purpose is to launch programs.


  • An alias is:

    • substitute a short command for a long one alias h=history

    • Create a single command for a series of commands alias home=“cd;ls”

    • Create alternate forms of existing commands alias copy=‘cp –i’

  • When an alias is set from the command line, it is activated only for the shell in which the alias is created.


  • To display alias:

    • alias

  • To Turn off:

    • unalias

  • To temporarily bypass the alias and use the original version of a command

    • alias ls=‘ls-l’

    • \ls home/dir1

History and repeating commands
History and Repeating Commands

  • The history feature in the Korn and Bash shells keeps a record of the exact command lines with an event number.

  • In the Korn shell the history list is stored in the user's home directory in a file named ~/.sh_history. By default, the Korn shell keeps a record of the last 128 commands entered.

  • The Bash shell history list is stored in the user's home directory in a file named ~/.bash_history. By default, the Bash shell keeps a record of the last 1000 commands entered.

  • The number of commands stored in the history list file for both the Korn and Bash shells is determined by the HISTSIZE variable


  • Command Format: history [options]

    • [- number] –execute previous (number)

  • The r (repeat) command is one of many predefined aliases in the Korn shell. This command is similar to the F3 key in DOS.

    • r [number]

  • The simplest way to repeat commands in the Bash shell is to press the up arrow, or Ctrl+P keys, and down arrow, or Ctrl+N keys. The Bash shell offers additional features for repeating previous command lines not available in the Korn shell

    • !! -Executes the previous command

    • !* -repeats all arguments from the previous command

    • !$ -repeats the last argument from the previous command

    • !number – executes command number from the history list

    • !n:p - views command n from the history list without executing it

Editing the command line
Editing the Command Line

  • Both the Korn and Bash shells offer a more powerful way to edit previous commands with the command line editing feature.

  • When enabled from the command line, the command line editing feature is activated only for the shell in which it was set.

    • Command Format: set [- or +] o vi or set [- or +] o emacs

  • When command line editing has been turned on with the vi mode, pressing the Esc key activates the in line editor

  • Example:

    • more /usr/share/dict/worfs = creates error

    • set –o vi

    • more /usr/share/dict/worfs = use keystrokes to move cursor

Shell features

  • The Korn shell does not support the use of arrow keys. Therefore, the arrow keys cannot be used to reposition the cursor during line editing

Filename and command completion
Filename and Command Completion

  • Both the Korn and Bash shells contain another feature that completes the name of a file or command by turning on the command line editor.

  • To use the completion feature: 

    • Type a command, such as ls, cat, rm and so on, followed by one or more characters of a file name. 

    • Press the Esc and backslash keys (Esc \) in sequential order, for the Korn shell, or the Tab key, for the Bash shell. 

  • Another way to use the completion feature is to request the shell to display a list of files that matches the entered filename. To display this list the student uses Esc= for the Korn shell or Tab Tab, entered twice, in the Bash shell.

Shell initialization
Shell Initialization

  • When the shell starts executing, it is uninitialized, which means, several parameters required for proper operation are not defined.

  • Initialization defines parameters.

  • Init files are short to provide a complete working environment with as little overhead as possible.

Variables overview
Variables Overview

  • All the work that is done and processes that are executed from the time of log in to the time of log out are completed within an environment.

  • Within the environment are variables that shell programs and processes access for customization.

  • Shell variables are names that hold value so processes can function properly.

  • Many Global Variables are predefined and set automatically when the user logs in.


  • The standard for the Korn and Bash shells is to use capital letters for shell variable names. Command Format:PS1="MyPrompt$“

  • The unsetcommand removes the variable from the current shell and subshells

  • To display the value of a single variable, use the echo command echo $PS1 would return "MyPrompt$" assuming the PS1 variable was set to Myprompt$.

  • The dollar sign ($) metacharacter preceding a variable tells the shell to use the value of the variable, not the name of the variable.

  • To display all variables in the local shell and the variable's values, type the set command,

Environmental variables
Environmental Variables

  • Environment variables are global variables available to all shells and subshells, not just the local shell.

  • To make a variable known to a subshell, it must be exported with the export command.

    • $PS1=“myprompt”

    • export PS1

  • To have line numbers automatically turned on when starting vi, the student could set the ex initialization variable (EXINIT) and then export the variable:

    • $EXINIT='set number';export EXINIT

    • $echo $EXINIT set number

  • Environment variables and their values can be displayed:

    • export or env


  • Double quotes are used to print characters literally, including spaces


    • $echo “$STRING”

    • $MAY DAY

  • Single quotes are used to interpret any metacharacter (*,?,>,|, and so on) literally, and ignore any type of value evaluation

  • Back quote is used to assign output from system commands to variables

    • $echo `date`

    • Tue Nov 16 16:40:19 GMT 2004

  • Backslash stops the shell from misinterpreting the next character if it has special meaning to the shell

    • $echo \*


  • Exporting variables in an initialization file at login enables the variables to be used by the system, processes, scripts, users, and all shells.

  • Exporting variables at the command line makes the variables available to the current shell and all child processes and shells, not the parent shell.

Custom prompts
Custom Prompts

  • The default prompt for the Korn and Bash shell is the dollar sign ($). To customize the shell prompt, use shell prompt variable (PS1=value).

  • The PS1 variable can include a wide range of expressions, such as character strings, commands, or other variables.

  • The variable PS1 is a shell variable. Any change in the variable setting remains until the shell is exited or until a subshell is opened. 

  • Note that prompts all end in a dollar sign ($), representing the Korn or Bash shell.

Custom prompts1
Custom Prompts

  • For simple prompt settings in the Bash shell the student can also set the PS1 variable to: 

    • \u for username 

    • \d for the date

    • \h for the hostname 

    • \$ for the dollar sign 

    • \W for the working directory 

    • PS1=\u@\h\$ for example, would result in the prompt similar to jamie@colorado

Initialization files
Initialization Files

  • Variables are either predefined, usually global, and is recognized in any shell.

  • Users can customize many of these variables by placing them in a user init file.

  • Unlike variables, aliases and shell option settings cannot be exported or made available to all subshells.

  • In order to make aliases and shell options available in a subshell, they must be placed in a secondary initialization file that is read each time a subshell is started.

Initialization files1
Initialization Files

  • The shell reads these files when the user;

    • logs in (login script),

    • when a subshell is run from the login shell by the user or automatically by the system (environment script),

    • when a user logs out (logout script).

  • Only the Bash and C shell programs have logout scripts.

  • They are two types of init files:

    • System wide initialization files are maintained by a system administrator, stored in the /etc directory and are read first.

    • The user specific initialization files reside in a user's home director are read second.

Etc profile file
/etc/profile file

  • The primary system wide initialization file for Korn and Bash shell users is the /etc/profile file which contains configuration information.

  • The user specific initialization files are different for the Korn and Bash shells.

  • The main function:

    • Exports environment variables: such as LOGNAME for login name and PATH for default command path

    • Displays contents of /etc/motd file:

    • Checks for mail

    • Other one time only commands such as cal or banner "$LOGNAME", and so on.

Bash shell login
BASH shell login

  • .bash_profile - local global variables.

  • .bashrc – only interactive shells and user scripts read this file. It typically contains aliases, turns on shell features, and sets the custom prompt.

  • If a Bash shell user wants to customize the environment, that user needs to create or modify the .bash_profile file and then the user must export the BASH_ENV variable, as shown here:

  • BASH_ENV =$HOME/.bashrc;export BASH_ENV

Bash shell login1
BASH shell login

  • To have the system reread the .bash_profile or .bashrc file after changes have been made the user can either log out and log back in or type the following from the command line:

    • $. (dot) ~/.bash_profile or $source ~/.bash_profile

    • $. (dot) ~/.bashrc or $source ~/.bashrc

  • A .bash_logout file is available for Bash shell users that allows for customization after the user logs out. Clear the screen and print "Bye", for instance

Korn user init files
Korn User Init Files

  • If a Korn shell user wants to customize the environment, that user needs to create or modify the .profile file and then the user must export the ENV variable, as shown here:

    • ENV =$HOME/.kshrc;export ENV

  • Korn shell specific commands and features should be placed in the .kshrc file. The .kshrc file automatically is read each time a new shell, such as a new Terminal window, or subshell is started, so there is nothing to export.

Korn shell
Korn Shell

  • The contents of the .kshrc file typically include the following:

    • A customized prompt

    • Custom variables

    • Aliases

  • The .profile file is read only once, while the .kshrc file is read every time a new Korn shell is started. To have the system reread the .kshrc or .profile files after changes have been made the user either can log out and log back in or can type the following from the command line:

    • $. (dot) ~/.kshrc (or $. .kshrc from the home directory)

    • $. (dot) ~/.profile (or $. .profile from the home directory)