SlideShare a Scribd company logo
Sixth Lecture
Intro to bash shell programming
Sabah Anwer Abdulkareem
University of Diyala, College of
Engineering, Department of
Computer Engineering
Intro to shell scripts
• Shell is a UNIX term for an interface between a user and an
operating system service. Shell provides users with an
interface and accepts human-readable commands into the
system and executes those commands which can run
automatically and give the program’s output in a shell script..
• An Operating is made of many components, but its two prime components
are –
• Kernel
• Shell
Components of Shell Program
•A Kernel is at the nucleus of a computer. It
makes the communication between the
hardware and software possible. While the
Kernel is the innermost part of an operating
system, a shell is the outermost one.
•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.
• The Shell wraps around the delicate interior of an Operating system
protecting it from accidental damage. Hence the name Shell.
Linux shell
Types of Shell
There are two main shells in Linux:
1. The 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)
2. The 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
How to Write Shell Script in Linux/Unix
• Shell Scripts are written using text editors. On your Linux system,
open a text editor program, open a new file to begin typing a shell
script or shell programming, then give the shell permission to execute
your shell script and put your script at the location from where the
shell can find it.
• Let us understand the steps in creating a Shell Script:
• Create a file using a vi editor(or any other editor). Name script file
with extension .sh
• Start the script with #! /bin/sh
• Write some code.
• Save the script file as filename.sh
• For executing the script type bash filename.sh
• “#!” 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.
• Let’s create a small script –
•#!/bin/sh
•ls
• Let’s see the steps to create Shell Script Programs in Linux/Unix –
mment
OR
Commenting is important in any program. In Shell programming, the syntax to add a comment is
# comment
Let understand this with an example.
Ctrl+x
shell script programming introduction and fundamentals
shell script programming introduction and fundamentals
the following creates a shell variable and then prints it:
variable ="Hello"
echo $variable
Below is a small script which will use a variable.
For example,
#!/bin/sh
echo "what is your name?"
read name
echo "How do you do, $name?"
read remark
echo "I am $remark too!"
shell script programming introduction and fundamentals
Summary:
• Kernel is the nucleus of the operating systems, and it communicates
between hardware and software
• Shell is a program which interprets user commands through CLI like Terminal
• The Bourne shell and the C shell are the most used shells in Linux
• Linux Shell scripting is writing a series of command for the shell to execute
• Shell variables store the value of a string or a number for the shell to read
• Shell scripting in Linux can help you create complex programs containing
conditional statements, loops, and functions
• Basic Shell Scripting Commands in Linux: cat, more, less, head, tail, mkdir,
cp, mv, rm, touch, grep, sort, wc, cut and, more.
Variables
shell script programming introduction and fundamentals

More Related Content

PPT
Shell and its types in LINUX
PPTX
Shell & Shell Script
PPTX
Shell & Shell Script
PPTX
Shell scrpting(payal harne)
PPTX
BWU_BTA_22_508_cSd how os are implemented.pptx
PDF
Introduction to Shell Scripting: All About It
PDF
Linux systems - Getting started with setting up and embedded platform
PPT
Chap06
Shell and its types in LINUX
Shell & Shell Script
Shell & Shell Script
Shell scrpting(payal harne)
BWU_BTA_22_508_cSd how os are implemented.pptx
Introduction to Shell Scripting: All About It
Linux systems - Getting started with setting up and embedded platform
Chap06

Similar to shell script programming introduction and fundamentals (20)

PPT
UnixShells.pptfhfehrguryhdruiygfjtfgrfjht
PPT
UnixShells.ppt
PDF
60761 linux
PDF
Unixshellscript 100406085942-phpapp02
PPTX
Licão 02 shell basics bash intro
PPTX
Bash shell scripting
ODP
Shellscripting
PDF
Bn1025 demo basic unix
PPT
Shell Basics
PDF
Shell Programming_Module2_Part2.pptx.pdf
PPTX
LINUX (1).pptxtytyyyyyyuuuuuuuuuuurttttttrrrrrr
PPTX
Shell programing|Shel Scripting
PPTX
Shell Scripting and Programming.pptx
PPTX
Shell Scripting and Programming.pptx
PPTX
Linux Desktop Operation - Session 1
PDF
Inside+Linux for newbiew who wants to become IT
PPTX
PPT of linux commands by Don Johnson.pptx
PDF
Course 102: Lecture 10: Learning About the Shell
PPT
02 linux desktop usage
PPTX
linux and shell programming for information.pptx
UnixShells.pptfhfehrguryhdruiygfjtfgrfjht
UnixShells.ppt
60761 linux
Unixshellscript 100406085942-phpapp02
Licão 02 shell basics bash intro
Bash shell scripting
Shellscripting
Bn1025 demo basic unix
Shell Basics
Shell Programming_Module2_Part2.pptx.pdf
LINUX (1).pptxtytyyyyyyuuuuuuuuuuurttttttrrrrrr
Shell programing|Shel Scripting
Shell Scripting and Programming.pptx
Shell Scripting and Programming.pptx
Linux Desktop Operation - Session 1
Inside+Linux for newbiew who wants to become IT
PPT of linux commands by Don Johnson.pptx
Course 102: Lecture 10: Learning About the Shell
02 linux desktop usage
linux and shell programming for information.pptx
Ad

Recently uploaded (20)

PDF
01-Introduction-to-Information-Management.pdf
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
Institutional Correction lecture only . . .
PDF
Computing-Curriculum for Schools in Ghana
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Basic Mud Logging Guide for educational purpose
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Pre independence Education in Inndia.pdf
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
PPH.pptx obstetrics and gynecology in nursing
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
RMMM.pdf make it easy to upload and study
PPTX
GDM (1) (1).pptx small presentation for students
01-Introduction-to-Information-Management.pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Institutional Correction lecture only . . .
Computing-Curriculum for Schools in Ghana
STATICS OF THE RIGID BODIES Hibbelers.pdf
TR - Agricultural Crops Production NC III.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Basic Mud Logging Guide for educational purpose
2.FourierTransform-ShortQuestionswithAnswers.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
human mycosis Human fungal infections are called human mycosis..pptx
O7-L3 Supply Chain Operations - ICLT Program
Final Presentation General Medicine 03-08-2024.pptx
Pre independence Education in Inndia.pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPH.pptx obstetrics and gynecology in nursing
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
RMMM.pdf make it easy to upload and study
GDM (1) (1).pptx small presentation for students
Ad

shell script programming introduction and fundamentals

  • 1. Sixth Lecture Intro to bash shell programming Sabah Anwer Abdulkareem University of Diyala, College of Engineering, Department of Computer Engineering
  • 2. Intro to shell scripts • Shell is a UNIX term for an interface between a user and an operating system service. Shell provides users with an interface and accepts human-readable commands into the system and executes those commands which can run automatically and give the program’s output in a shell script.. • An Operating is made of many components, but its two prime components are – • Kernel • Shell Components of Shell Program
  • 3. •A Kernel is at the nucleus of a computer. It makes the communication between the hardware and software possible. While the Kernel is the innermost part of an operating system, a shell is the outermost one.
  • 4. •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.
  • 5. • The Shell wraps around the delicate interior of an Operating system protecting it from accidental damage. Hence the name Shell. Linux shell
  • 6. Types of Shell There are two main shells in Linux: 1. The 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) 2. The 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
  • 7. How to Write Shell Script in Linux/Unix • Shell Scripts are written using text editors. On your Linux system, open a text editor program, open a new file to begin typing a shell script or shell programming, then give the shell permission to execute your shell script and put your script at the location from where the shell can find it. • Let us understand the steps in creating a Shell Script: • Create a file using a vi editor(or any other editor). Name script file with extension .sh • Start the script with #! /bin/sh • Write some code. • Save the script file as filename.sh • For executing the script type bash filename.sh
  • 8. • “#!” 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. • Let’s create a small script – •#!/bin/sh •ls
  • 9. • Let’s see the steps to create Shell Script Programs in Linux/Unix – mment OR
  • 10. Commenting is important in any program. In Shell programming, the syntax to add a comment is # comment Let understand this with an example. Ctrl+x
  • 13. the following creates a shell variable and then prints it: variable ="Hello" echo $variable Below is a small script which will use a variable. For example, #!/bin/sh echo "what is your name?" read name echo "How do you do, $name?" read remark echo "I am $remark too!"
  • 15. Summary: • Kernel is the nucleus of the operating systems, and it communicates between hardware and software • Shell is a program which interprets user commands through CLI like Terminal • The Bourne shell and the C shell are the most used shells in Linux • Linux Shell scripting is writing a series of command for the shell to execute • Shell variables store the value of a string or a number for the shell to read • Shell scripting in Linux can help you create complex programs containing conditional statements, loops, and functions • Basic Shell Scripting Commands in Linux: cat, more, less, head, tail, mkdir, cp, mv, rm, touch, grep, sort, wc, cut and, more.

Editor's Notes

  • #6: command execution program, often called a command interpreter )