You are on page 1of 17

Chapter 7

Shell Basics

What is the shell?
• A shell is an interactive program that serves as a command line interpreter • It is separate from the operating system • A shell’s job is to allow you to type in your command, perform several functions, and pass the interpreted command to the operating system (kernel) for execution.

Commonly Used Shells
• • • • • /usr/bin/sh /usr/bin/ksh /usr/bin/csh /bin/bash /usr/old/bin/sh POSIX shell Korn shell C shell Bourne (Again) SHell Bourne shell

POSIX shell
The POSIX shell is a POSIX-compliant command programming language and commands interpreter. It can execute commands read from a terminal or a file. It contains a history mechanism, supports job control, and provides various other useful features.

Korn Shell
The Korn shell is a command programming language and commands interpreter. It can execute commands read from a terminal or a file. Like the POSIX shell, it contains a history mechanism, supports job control and provides various other useful features. The Korn shell was developed by David Korn of AT&T Bell Labs.

Bourne shell
• Lacks many features contained in the POSIX and Korn shells. • Developed by Stephen R. Bourne • It was the original shell available on the AT&T releases of UNIX

C Shell
• A command language interpreter that incorporates a command history buffer • C-language-like syntax, and job control facilities • developed by William Joy of the University of California at Berkeley

Comparison of Shell Features
Features
Command History
Line Editing

Description
A feature allowing commands to be stored in a buffer, then modified and reused
The ability to modify the current or previous command lines with a text editor

Posix

Bour ne

Kor n

C

Yes
Yes

No
No

Yes
Yes

Yes
No

File name completion
Alias command

The ability to automatically finish typing file names in command lines
A feature allowing users to rename commands, automatically include command options, or abbreviate long command line

Yes
Yes

No
No

Yes
Yes

Yes
Yes

Restricted shells
Job control

A security feature providing a controlled environment with limited capabilities
Tools for tracking and accessing processes that run in the background

Yes
Yes

Yes
No

Yes
Yes

No
Yes

Aliasing
• An alias is a new name for a command Syntax: $ alias [name[=string]] Example: $ alias dir=ls $ alias d=“ls –l” $ alias mroe=more • alias - displays aliases currently defined $ alias

Command History
• The shell keeps a history file of commands that you enter. • The history command displays the last 16 commands. • You can recall, edit, and re-enter previously entered commands Syntax: $ history [-n| a z]

Example: $ history –2 $ history 3 5

Re-entering commands
Type r c to re-enter command number c
Example: $ history 3 5 $ r 4

Recalling Commands
• Uses the history mechanism • Must have the EDITOR environment variable set. $ EDITOR=vi $ export EDITOR -At $, press ESC and use normal vi commands to scroll through previous commands. k -scrolls backwards j -scrolls forward -Press RETURN to execute the command.

Command line editing
• Provides the ability to modify text entered on current or previous • press ESC to enter command mode. • To recall press k, until the command appears • To position the cursor Use l or space to move right Use h or backspace to move left

Command line editing cont.
To modify text: -press x to delete a character -press i to insert or append -press ESC to stop adding characters -press return to execute the modified command

The User Environment
Your environment describes your session to the programs you run Syntax: $ env

Setting Shell Variables
• A shell variable is a name that represents a value • Some shell variables are defined during the login process • A user can define new shell variable Syntax: $ name=value $ PATH=/usr/bin/X11:/usr/bin $ PS1=“Jess$ “ No space before and after the = sign

Looking for commands
• whereis [-b| -m| -s] command
- Searches a list of directories for command

Examples: $ whereis if $ whereis ls $ whereis cd