• About WordPress
    • WordPress.org
    • Documentation
    • Support
    • Feedback
  • Log In
  • Register
  • Home
  • Courses
  • Past Paper
  • FYP
  • Interview Questions
  • University Events
  • Contact
  • Quiz & Assignment
Cuitutorial
  • Home
  • Courses
  • Past Paper
  • FYP
  • Interview Questions
  • University Events
  • Contact
  • Quiz & Assignment

Operating System

Home » Blog » Introduction To Shell Programming

Introduction To Shell Programming

  • Posted by saqib
  • Categories Operating System
  • Date November 1, 2022
  • Comments 6 comments

Kernel and Shell

An Operating is made of many components, but its two prime components are –

  • Kernel
  • Shell

  • A Kernel is at the nucleus of a computer.
  • It makes the communication between the hardware and software possible.
  • A shell in a Linux operating system takes input from you in the form of commands, processes it, and then gives an output.
  • It is the interface through which a user works on the programs, commands, and scripts.
  • A shell is accessed by a terminal which runs it.
  • When you run the terminal, the Shell issues a command prompt (usually $),where you can type your input, which is then executed when you hit the Enter key. The output or the result is thereafter displayed on the terminal.
  • While the Kernel is the innermost part of an operating system, a shell is the outermost one.

Types of Shell

There are two main shells in Linux:

  1. Bourne Shell:

The prompt for this shell is $ and its derivatives are listed below:

  • POSIX shell also is known as sh
  • Korn Shell also knew as ksh
  • Bourne Again Shell also knew as bash (most popular)
  • Bourne shell (sh)
  1. C shell:

The prompt for this shell is %, and its subcategories are:

  • C shell also is known as csh
  • Tops C shell also is known as tcsh

Command To View Supported shell types by system

            cat /etc/shells

 

What Is Shell Scripting?

 

  • SHELL SCRIPTING is writing a series of commands 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.

 

steps in creating a Shell Script

  1. Create a file using a vi editor (or any other editor).  Name script file with extension .sh
  2. Start the script with #! /bin/sh
  3. Write some code.
  4. Save the script file as filename.sh
  5. For executing the script type bash filename.sh

 

#! operator

 

“#!” is an operator called shebang which directs the script to the interpreter location. So, if we use”#! /bin/sh” the script gets directed to the bourne-shell.

 

Example:

Let’s create a small script –

#!/bin/sh

ls

 

Adding shell comments

Commenting is important in any program. In Shell programming, the syntax to add a comment is

       #comment

 

Wildcards

There are some characters that are evaluated by the shell in a special way. They are called shell metacharacters or “wildcards.”

These characters are neither numbers nor letters.

For example

the *, ?, and [ ] are used for filename expansion.

The >, >>, and | symbols are used for standard I/O redirection and pipes.

To prevent these characters from being interpreted by the shell they must be quoted.

What are Shell Variables?

Variables store data in the form of characters and numbers. Similarly, Shell variables are used to store information and they can used by the shell only.

For example, the following creates a shell variable and then prints it:

variable =”Hello”

echo $variable

 

Example

#!/bin/sh

echo “what is your name?”

read name

echo “How do you do, $name?”

read remark

echo “I am $remark too!”

Lab Tasks:

  • Write a shell script that prints “Shell Scripting is Fun!” on the screen

 

  • Store the output of the command “hostname” in a variable. Display “This script is running on _.” where “_” is the output of the “hostname” command.

 

  • Write a shell program that adds two numbers.

 

  • Write a shell program that takes 2 integer values from user and then show the sum of values.

Related links

  • Operating System-Functions and History
  • Generations of Operating System
  • Functions of an Operating System
  • Components of Operating System
  • Types of Operating System
  • Services of Operating System
  • Properties of Operating System
  • Processes in Operating System
  • Process Scheduling in Operating System

Lab Practice Task

  • Introduction to Linux Ubunto
  • Installation with virtual Box
  • Writing Linux Commands
  • Navigation in File System and Directory Management in Ubunto using CLI
  • File Handling and I/O Redirection In Ubunto
  • File Access Permission in Linux
  • Text Processing Tools and Basic System Configuration Tools in Linux
  • Package Management in Linux
  • How to manage processes in Linux
  • Compiling and Executing C++ programs in Linux
  • System Calls
  • Introduction To Shell Programming 
  • Share:
author avatar
saqib

Previous post

System Calls in linux
November 1, 2022

Next post

Operating System Topics
November 1, 2022

You may also like

Aging in operating system
6 January, 2023

Aging in operating system In Operating systems, Aging is a scheduling technique used to avoid Starvation. Fixed priority scheduling is a scheduling discipline in which tasks queued for utilizing a system resource is assigned each priority. A task with a …

Starvation in operating system
6 January, 2023

Starvation in operating system It is a problem when the low-priority process gets jammed for a long duration of time because of high-priority requests being executed. A stream of high-priority requests stops the low-priority process from obtaining the processor or …

Dead Lock in operating system
3 January, 2023

Dead Lock in operating system A Deadlock is a situation where each of the computer process waits for a resource which is being assigned to some another process. In this situation, none of the process gets executed since the resource …

    6 Comments

Leave A Reply Cancel reply

You must be logged in to post a comment.

admin@cuitutorial.com
Facebook-f Twitter Youtube Linkedin Instagram Stack-overflow Pinterest Github Quora Whatsapp
Courses
  • All Courses
  • Past Paper
  • Final year projects
  • Interview Questions
  • Contact
Important Pages
  • Privacy Policy
  • Terms of Service
  • Cookie Policy
Links
  • University Events
  • Team
Education & learning platform for All Computer science subjects
Final year projects
Past Paper
Interview questions
Programming, C/C++, Asp.net/MVC. Android, MySql, Jquery, Ajax, javascript, Php, Html5, Bootstrap4.
NTS, GAT, PPSC, FPSC

Copyright © 2021 | Cuitutorial