Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 7

4. What is Shell?

Shell Prompt
Shell Types
Shell Scripts
Comments
A Shell provides you with an interface to the Unix system. It gathers input from you and executes programs based on that input.
When a program finishes executing, it displays that program's output.

Shell is an environment in which we can run our commands, programs, and shell scripts. There are different flavors of a shell, just
as there are different flavors of operating systems. Each flavor of shell has its own set of recognized commands and functions.

Shell Prompt
The prompt, $, which is called the command prompt, is issued by the shell. While the prompt is displayed, you can type a
command.
Shell reads your input after you press Enter. It determines the command you want to execute by looking at the first word of your
input.

1. Define shell
2. Discuss how shell prompt works
Shell Types
In Unix, there are two major types of shells −
•Bourne shell − If you are using a Bourne-type shell, the $ character is the default prompt.
•C shell − If you are using a C-type shell, the % character is the default prompt.

The Bourne Shell has the following subcategories −


 Bourne shell (sh)
 Korn shell (ksh)
 Bourne Again shell (bash)
 POSIX shell (sh)

The different C-type shells follow −


 C shell (csh)
 TENEX/TOPS C shell (tcsh)

1. List types of shell


Shell Scripts
 Shell scripting is writing a series of command for the shell to execute.
 It can combine lengthy and repetitive sequences of commands into a single and simple script, which can be stored and
executed anytime. This reduces the effort required by the end user.
 Commands in shell script are listed in the order of execution.
 A good shell script will have comments, preceded by # sign, describing the steps
 There are conditional tests, such as value A is greater than value B, loops allowing us to go through massive
amounts of data, files to read and store data, and variables to read and store data, and the script may include
functions.

Example :
Assume we create a test.sh script (file with extension sh). Note all the scripts would have the .sh extension. Before you add
anything else to your script, you need to alert the system that a shell script is being started.

Command : #!/bin/sh

This tells the system that the commands that follow are to be executed by the Bourne shell.
Shell Comments:
You can put your comments in your script using #

Example: # script to print number of words in file

Let us create our first shell script to print “hello world”

Step 1: create a file with extension .sh using vi editor. First Line of file should be #!/bin/sh

Step2 : Write script code to print “ Hello World “ message on screen

Echo “Hello world”

Step3: Save file .sh

Step 4: execute file using command “ bash filename.sh “


1. Write steps to create a shell script and execute it.
What are Shell Variables?
As discussed earlier, Variables store data in the form of characters and numbers. Similarly, Shell variables are used to store
information and they can by the shell only.

Example :

1.
1. Write shell script to accept Username and display “Hello Username “
message on screen
variable="Hello"
echo $variable

2. #!/bin/sh
echo "what is your name?"
read name
echo "How do you do, $name? “

You might also like