You are on page 1of 6

Chapter – II

Shell functionality in regards to


o Command interpretation (Enabling Command Line Editing)
1. Visual
2. Set

1. Visual:- The Korn shell checks to see if this variable ends with vi or macs.

 VISUAL=$(whence emacs)

or

 VISUAL=$(whence vi)

2. Set : -The second way of selecting an editing mode is to set the option explicitly with
the set -o command:

$ set -o emacs

or

$ set -o vi

o Filename expansion
If you want a command to work with a group of files. Wildcards are used to create
a filename expansion pattern: a series of characters and wildcards that expands to a
list of filenames.
Eg:- / etc/*

Available wildcards include the following:

* - Matches any group of 0 or more characters.

? - Matches exactly one character.

[...] - If you enclose some characters in brackets, the result is a wildcard that matches those
characters. For example,[abc] matches either a, or b, or c. If you add a ^ after the first
bracket, the sense is reversed; so [^abc] matches any character that is not a, b, or c. You can
include a range, such as [a-j], which matches anything between a and j. The match is case
sensitive, so to allow any letter, you must use [a-zA-Z].

Examples:

*.txt - This will give you a list of all filenames that end in .txt, since the * matches anything at all.

*.[h] - This gives a list of filenames that end in  .h .

Page 1 of 6
[^a] - This gives you all a -letter filenames that do not begin with a.

a* - This gives you every filename that starts with a, regardless of how many letters it has.

 Redirection and Pipes


Almost all commands produces the output to screen or take input from the keyboard, but in
Linux it is possible to send output to a file or to read input from a file. Each shell command
has its own input and outputs. Before a command is executed, its input and output may be
redirected using a special notation interpreted by the shell. For example, sending output of
date command to a file instead of to the screen. Changing the default path of input or output
is called redirection.

 In Linux everything is a file.


 Your hardware is also a file:

 0 - Input - Keyboard (stdin)

 1 - Output - Screen (stdout)

 2 - Error - Screen (stderr)

 The above three numbers are standard POSIX numbers and also known as file
descriptors (FD). Every Linux command at least open the above streams to talk with users
or other system programs.

Integer value
Standard File Descriptor
Meaning
File Number

Page 2 of 6
Read input from a file (the
stdin 0
default is keyboard)

Send data to a file (the


stdout 1
default is screen).

Send all error messages to a


stderr 2
file (the default is screen).

You can manipulate the final result by redirecting input and output.

Standard Input: -

 Standard input is the default input method, which is used by all commands to read its
input.
 It is denoted by zero number (0).

 Also known as stdin.

 The default standard input is the keyboard.

Standard Output:-

 Standard output is used by a command to writes (display) its output.


 The default is the screen.

 It is denoted by one number (1).

 Also known as stdout.

 The default standard output is the screen.

Standard Error:-

 Standard error is the default error output device, which is used to write all system
error messages.
 It is denoted by two number (2).

 Also known as stderr.

 The default standard input is the screen or monitor.

 Quoting mechanisms

Page 3 of 6
There are three types of quotes:
Quote
Name Meaning Example (type at shell prompt)
type

The double quote ( "quote" )


protects everything enclosed
The double quotes allowes to print the
between two double quote marks
value of $SHELL variable, disables the
except $, ', " and \.Use the double
The meaning of wildcards, and finally
quotes when you want
" double allows command substitution.
only variables and command
quote
substitution.
echo "Today is $(date)"
* Variable - Yes
 
* Wildcards - No
* Command substitution - yes

The single quote ( 'quote' ) The single quotes prevents displaying


protects everything enclosed variable $SHELL value, disabled the
between two single quote marks. meaning of wildcards /etc/*.conf, and
The single It is used to turn off the special finally command substitution ($date)
' itself. 
quote meaning of all characters.
* Variable - No
* Wildcards - No echo 'Today is $(date)'
* Command substitution - No  

You can use \ before dollar sign to tell


the shell to have no special meaning.
Use backslash to change the Disable the meaning of the next
special meaning of the characters character in $date (i.e. do not display
The value of $date variable):
\ or to escape special characters
Backslash
within the text such as quotation
marks. echo “Today is /$(date)”

The Backslash

The backslash ( \ ) alters the special meaning of the ' and " i.e. it will escape or cancel the
special meaning of the next character.

Example:-
leo@leo-desktop:~$ echo "Todays Date is $(date)"
Todays Date is Thu Dec 2 14:20:11 EAT 2010
Page 4 of 6
leo@leo-desktop:~$ echo Todays Date is $(date)
Todays Date is Thu Dec 2 14:20:21 EAT 2010

leo@leo-desktop:~$ echo 'Todays Date is $(date)'


Todays Date is $(date)

leo@leo-desktop:~$ echo 'Todays Date is /$(date)'


Todays Date is /$(date)

leo@leo-desktop:~$ echo "Todays Date is /$(date)"


Todays Date is /Thu Dec 2 14:20:52 EAT 2010

leo@leo-desktop:~$ echo Todays Date is /$(date)


Todays Date is /Thu Dec 2 14:21:08 EAT 2010

leo@leo-desktop:~$ echo "Todays Date is \$(date)"


Todays Date is $(date)

leo@leo-desktop:~$ echo 'Todays Date is \$(date)'


Todays Date is \$(date)

leo@leo-desktop:~$ echo Todays Date is \$(date)


bash: syntax error near unexpected token `('

 Entering program code and commands & Shell program execution


procedures
In order to type the command you should enter into the command mode(Terminal mode).
There after you will get a prompt same as that of the command prompt with a $ symbol as
specified below also with its path and the user in it.

Student$student-desktop:$

This is the prompt in which you will type the commands.

Example :-
$ date – used for displaying the date.
$ cal – used for the purpose of displaying the calendar
The terminal in which you will type the programs for the purpose of displaying the
commands and the output of the commands.

Entering shell programs.

Enter into the terminal mode and then go for entering the command as

1. $ vi aaa.sh

vi – starting/editing the program.

aaa – Program name.

Page 5 of 6
.sh – goes for the extension of shell.

2. Press Insert key


3. Start typing the program.
4. Press Esc key
5. Shift :
6. Press wq

After execution of this the program is been saved in the program name
with the extension of sh

Executing shell program

1. $ sh aaa.sh

sh – start executing the shell program


aaa – refers for the program name
.sh – refers for the shell extension.

As you execute this you will get the program been implemented.

Page 6 of 6

You might also like