SlideShare a Scribd company logo
Shell
• A shell is a command-line interface (CLI) program that interprets user commands and
executes them.
• It acts as an intermediary between the user and the operating system (OS), allowing users
to interact with the OS by typing commands into a text-based interface rather than using
graphical user interfaces (GUIs).
• Graphical Shell
• Command line shell
• A shell provides a way for users to access the functionality and services of the underlying
operating system through commands and scripts.
Shell features
• Command Execution: Shells execute commands entered by the user or read from scripts.
• Input/Output Redirection: Shells allow users to redirect input and output streams to and from files
or other processes.
• Command Pipelines: Shells support chaining commands together using pipes (|) to pass the output
of one command as the input to another.
• Variables and Environment Control: Shells support variables for storing data and controlling the
environment in which commands are executed.
• Control Structures: Shells provide control structures such as loops and conditional statements for
scripting and automation.
• Job Control: Shells allow users to manage processes, including running them in the background,
suspending them, or bringing them to the foreground.
Common types of shells
• Bash (Bourne Again Shell): The default shell for most Linux distributions and macOS. It is a
powerful and widely used shell with extensive features and capabilities.
• Zsh (Z Shell): A highly customizable shell with features for improved interactive use and scripting.
• csh (C Shell): One of the earliest Unix shells, developed by Bill Joy for the BSD Unix system. It has a
syntax similar to the C programming language.
• tcsh (TENEX C Shell): An enhanced version of csh, adding features such as command line editing
and history.
Shell Variables
• Shell variables in C shell are entities that store data, such as strings or integers, for later
use within the shell environment. They can be set and accessed using the set command
and referenced using the $ symbol.
For example:
set variable_name = value
Example:
set name = "John"
set age = 25
Variable Access:
• To access the value of a variable, you prepend a dollar sign ($) to its name:
echo $variable_name
echo $name
John
Variable Substitution:
• Variables can be substituted within strings using curly braces ({}) to distinguish
the variable name from surrounding text. This is useful when constructing complex
strings:
echo "My name is ${name} and I am ${age} years old.“
output:
My name is John and I am 25 years old.
certain rules for naming Variables
• Start with a Letter or Underscore: Variable names must begin with a letter (a-z or A-Z) or an underscore (_).
• Subsequent Characters: After the initial letter or underscore, variable names can include letters, digits (0-9), or
underscores.
• Case Sensitivity: Shell variables are typically case-sensitive. For instance, $var, $VAR, and $vAr would refer to
different variables.
• Reserved Keywords: Avoid using shell keywords or reserved words as variable names. These are words with
special meaning to the shell, such as if, while, for, do, done, case, etc.
• Avoid Special Characters: It's best to avoid using special characters such as spaces, punctuation marks, or
operators in variable names. Stick to alphanumeric characters and underscores for simplicity and compatibility.
• Length: While there is no strict limit on the length of variable names, it's recommended to keep them reasonably
short and descriptive for readability.
certain rules for naming Variables
• Valid variable names:
• name
• age
• _count
• var123
• _my_var
• Invalid variable names:
• 1var # Cannot start with a digit
• my-var # Hyphens are not allowed
• my var # Spaces are not allowed
• if # Reserved keyword
Parameter shell commands,
• Parameter shell commands, also known as control flow or flow control commands, are fundamental
constructs in shell scripting that allow you to control the flow of execution based on conditions, loop
through sets of data, and manipulate the behavior of your script.
• if, while, until, for, break, continue
if
• “if-else” is dealing with two-part of the executions. If the “if-else “condition is “true” then the first
group of statements will execute. If the condition is “false” then the second group of statements will
execute.
if
Syntax:
• The if statement starts with the keyword if.
• Inside square brackets [ ], you specify the condition that needs to be evaluated. This condition can
involve comparisons, logical operators, or any other expression that evaluates to true or false.
• After the condition, the then keyword marks the beginning of the code block to be executed if the
condition is true.
• The fi keyword marks the end of the if statement.
• It's important to note that spaces are required around the square brackets [ ] and after the if, then,
and fi keywords for proper syntax.
If example
echo "Enter a number:"
read number
if [ $number -gt 0 ]; then
echo "The number is positive."
elif [ $number -lt 0 ]; then
echo "The number is negative."
else
echo "The number is zero."
fi
while
• The while loop in shell scripting is used to execute a block of code repeatedly as long as a specified
condition is true.
• The while keyword marks the beginning of the loop.
• Inside square brackets [ ], you specify the condition that needs to be evaluated.
• This condition can involve comparisons, logical operators, or any other expression that evaluates to
true or false.
• After the condition, the do keyword marks the beginning of the code block to be executed while the
condition is true.
• At the end of the code block, the done keyword marks the end of the loop.
• It's important to note that spaces are required around the square brackets [ ] and after the while, do,
and done keywords for proper syntax.
while
Example script using a while loop to count from 1 to 5
• count=1
• while [ $count -le 5 ]; do
• echo "Count is $count"
• count=$((count + 1))
• done
Output:
Count is 1
Count is 2
Count is 3
Count is 4
Count is 5
until
• The until loop in shell scripting is similar to the while loop but with an opposite condition.
• It executes a block of code repeatedly until a specified condition becomes true.
• The until keyword marks the beginning of the loop.
• Inside square brackets [ ], you specify the condition that needs to be evaluated.
• This condition can involve comparisons, logical operators, or any other expression that evaluates to true or false.
• After the condition, the do keyword marks the beginning of the code block to be executed until the condition
becomes true.
• At the end of the code block, the done keyword marks the end of the loop.
• It's important to note that spaces are required around the square brackets [ ] and after the until, do, and done
keywords for proper syntax.
until
• count=1
• until [ $count -gt 5 ]; do
• echo "Count is $count"
• count=$((count + 1))
• done
Output:
Count is 1
Count is 2
Count is 3
Count is 4
Count is 5
for
• The for loop in shell scripting is used to iterate over a list of items and execute a block of code for each
item in the list.
• The for keyword marks the beginning of the loop.
• variable is a variable that will take on each value in the list during each iteration of the loop.
• list is a sequence of items separated by spaces.
• After the list, the do keyword marks the beginning of the code block to be executed for each item in the
list.
• At the end of the code block, the done keyword marks the end of the loop.
• It's important to note that spaces are required after the for, in, do, and done keywords for proper
for
• for num in 1 2 3 4 5; do
• echo "Number is $num"
• Done
Outuput
Number is 1
Number is 2
Number is 3
Number is 4
Number is 5
• The for loop iterates over the list of numbers 1 2 3 4 5.
• During each iteration, the variable num takes on the value of each number in the list.
• Inside the loop, it executes the code block, which prints "Number is ..." for each value of num.
break
• In shell scripting, the break statement is used to exit or terminate a loop prematurely.
• It is typically used within a loop (such as for, while, or until) to stop the loop execution based on
certain conditions
• count=1
• while [ $count -le 10 ]; do
• echo "Count is $count"
• if [ $count -eq 5 ]; then
• break # Exit loop if count reaches 5
• fi
• count=$((count + 1))
• done
OUTPUT
Count is 1
Count is 2
Count is 3
Count is 4
Count is 5
continue
• In shell scripting, the continue statement is used to skip the remaining code within a loop iteration
and proceed with the next iteration of the loop.
• It is typically used within a loop (such as for, while, or until) to skip certain iterations based on
specific conditions
• for (( i=1; i<=10; i++ )); do
• if [ $((i % 2)) -ne 0 ]; then
• continue # Skip odd numbers
• fi
• echo "Number is $i"
• done

More Related Content

Similar to Shell Programming Language in Operating System .pptx (20)

PPT
34-shell-programming asda asda asd asd.ppt
poyotero
 
PPT
34-shell-programming.ppt
KiranMantri
 
PPT
Unix And Shell Scripting
Jaibeer Malik
 
PPTX
shellScriptAlt.pptx
NiladriDey18
 
PDF
Shell Scripting Intermediate - RHCSA+.pdf
RHCSA Guru
 
PPT
1 4 sp
Bhargavi Bbv
 
PPTX
Case, Loop & Command line args un Unix
Vpmv
 
PPTX
Unix shell scripts
Prakash Lambha
 
DOCX
of 70UNIX Unbounded 5th EditionAmir Afzal .docx
MARRY7
 
DOCX
of 70UNIX Unbounded 5th EditionAmir Afzal .docx
adkinspaige22
 
PPT
Introduction to shell scripting ____.ppt
nalinisamineni
 
PPT
Chap06
Dr.Ravi
 
PPTX
Shell scripting
Mufaddal Haidermota
 
ODP
Shellscripting
Narendra Sisodiya
 
PPT
Bash Programming
Kiplangat Chelule
 
PDF
Operating_System_Lab_ClassOperating_System_2.pdf
DharmatejMallampati
 
PPTX
Scripting ppt
anamichintu
 
PPT
2-introduction_to_shell_scripting
erbipulkumar
 
PPTX
First steps in C-Shell
Brahma Killampalli
 
34-shell-programming asda asda asd asd.ppt
poyotero
 
34-shell-programming.ppt
KiranMantri
 
Unix And Shell Scripting
Jaibeer Malik
 
shellScriptAlt.pptx
NiladriDey18
 
Shell Scripting Intermediate - RHCSA+.pdf
RHCSA Guru
 
1 4 sp
Bhargavi Bbv
 
Case, Loop & Command line args un Unix
Vpmv
 
Unix shell scripts
Prakash Lambha
 
of 70UNIX Unbounded 5th EditionAmir Afzal .docx
MARRY7
 
of 70UNIX Unbounded 5th EditionAmir Afzal .docx
adkinspaige22
 
Introduction to shell scripting ____.ppt
nalinisamineni
 
Chap06
Dr.Ravi
 
Shell scripting
Mufaddal Haidermota
 
Shellscripting
Narendra Sisodiya
 
Bash Programming
Kiplangat Chelule
 
Operating_System_Lab_ClassOperating_System_2.pdf
DharmatejMallampati
 
Scripting ppt
anamichintu
 
2-introduction_to_shell_scripting
erbipulkumar
 
First steps in C-Shell
Brahma Killampalli
 

More from SherinRappai (20)

PPTX
Shells commands, file structure, directory structure.pptx
SherinRappai
 
PPTX
Types of NoSql Database available.pptx
SherinRappai
 
PPTX
Introduction to NoSQL & Features of NoSQL.pptx
SherinRappai
 
PPTX
Clustering, Types of clustering, Types of data
SherinRappai
 
PPTX
Association rule introduction, Market basket Analysis
SherinRappai
 
PPTX
Introduction to Internet, Domain Name System
SherinRappai
 
PPTX
Cascading style sheet, CSS Box model, Table in CSS
SherinRappai
 
PPTX
Numpy in python, Array operations using numpy and so on
SherinRappai
 
PPTX
Functions in python, types of functions in python
SherinRappai
 
PPTX
Extensible markup language ppt as part of Internet Technology
SherinRappai
 
PPTX
Java script ppt from students in internet technology
SherinRappai
 
PPTX
Building Competency and Career in the Open Source World
SherinRappai
 
PPTX
How to Build a Career in Open Source.pptx
SherinRappai
 
PPTX
Issues in Knowledge representation for students
SherinRappai
 
PPTX
A* algorithm of Artificial Intelligence for BCA students
SherinRappai
 
PPTX
Unit 2.pptx
SherinRappai
 
PPTX
COMPUTING AND PROGRAMMING FUNDAMENTAL.pptx
SherinRappai
 
PPTX
Clustering.pptx
SherinRappai
 
PPTX
neuralnetwork.pptx
SherinRappai
 
PPTX
Rendering Algorithms.pptx
SherinRappai
 
Shells commands, file structure, directory structure.pptx
SherinRappai
 
Types of NoSql Database available.pptx
SherinRappai
 
Introduction to NoSQL & Features of NoSQL.pptx
SherinRappai
 
Clustering, Types of clustering, Types of data
SherinRappai
 
Association rule introduction, Market basket Analysis
SherinRappai
 
Introduction to Internet, Domain Name System
SherinRappai
 
Cascading style sheet, CSS Box model, Table in CSS
SherinRappai
 
Numpy in python, Array operations using numpy and so on
SherinRappai
 
Functions in python, types of functions in python
SherinRappai
 
Extensible markup language ppt as part of Internet Technology
SherinRappai
 
Java script ppt from students in internet technology
SherinRappai
 
Building Competency and Career in the Open Source World
SherinRappai
 
How to Build a Career in Open Source.pptx
SherinRappai
 
Issues in Knowledge representation for students
SherinRappai
 
A* algorithm of Artificial Intelligence for BCA students
SherinRappai
 
Unit 2.pptx
SherinRappai
 
COMPUTING AND PROGRAMMING FUNDAMENTAL.pptx
SherinRappai
 
Clustering.pptx
SherinRappai
 
neuralnetwork.pptx
SherinRappai
 
Rendering Algorithms.pptx
SherinRappai
 
Ad

Recently uploaded (20)

PPTX
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PDF
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
PDF
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
PPTX
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PDF
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PDF
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PPTX
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PDF
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
PPTX
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
PPTX
How to Set Maximum Difference Odoo 18 POS
Celine George
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
How to Set Maximum Difference Odoo 18 POS
Celine George
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
Ad

Shell Programming Language in Operating System .pptx

  • 1. Shell • A shell is a command-line interface (CLI) program that interprets user commands and executes them. • It acts as an intermediary between the user and the operating system (OS), allowing users to interact with the OS by typing commands into a text-based interface rather than using graphical user interfaces (GUIs). • Graphical Shell • Command line shell • A shell provides a way for users to access the functionality and services of the underlying operating system through commands and scripts.
  • 2. Shell features • Command Execution: Shells execute commands entered by the user or read from scripts. • Input/Output Redirection: Shells allow users to redirect input and output streams to and from files or other processes. • Command Pipelines: Shells support chaining commands together using pipes (|) to pass the output of one command as the input to another. • Variables and Environment Control: Shells support variables for storing data and controlling the environment in which commands are executed. • Control Structures: Shells provide control structures such as loops and conditional statements for scripting and automation. • Job Control: Shells allow users to manage processes, including running them in the background, suspending them, or bringing them to the foreground.
  • 3. Common types of shells • Bash (Bourne Again Shell): The default shell for most Linux distributions and macOS. It is a powerful and widely used shell with extensive features and capabilities. • Zsh (Z Shell): A highly customizable shell with features for improved interactive use and scripting. • csh (C Shell): One of the earliest Unix shells, developed by Bill Joy for the BSD Unix system. It has a syntax similar to the C programming language. • tcsh (TENEX C Shell): An enhanced version of csh, adding features such as command line editing and history.
  • 4. Shell Variables • Shell variables in C shell are entities that store data, such as strings or integers, for later use within the shell environment. They can be set and accessed using the set command and referenced using the $ symbol. For example: set variable_name = value Example: set name = "John" set age = 25
  • 5. Variable Access: • To access the value of a variable, you prepend a dollar sign ($) to its name: echo $variable_name echo $name John
  • 6. Variable Substitution: • Variables can be substituted within strings using curly braces ({}) to distinguish the variable name from surrounding text. This is useful when constructing complex strings: echo "My name is ${name} and I am ${age} years old.“ output: My name is John and I am 25 years old.
  • 7. certain rules for naming Variables • Start with a Letter or Underscore: Variable names must begin with a letter (a-z or A-Z) or an underscore (_). • Subsequent Characters: After the initial letter or underscore, variable names can include letters, digits (0-9), or underscores. • Case Sensitivity: Shell variables are typically case-sensitive. For instance, $var, $VAR, and $vAr would refer to different variables. • Reserved Keywords: Avoid using shell keywords or reserved words as variable names. These are words with special meaning to the shell, such as if, while, for, do, done, case, etc. • Avoid Special Characters: It's best to avoid using special characters such as spaces, punctuation marks, or operators in variable names. Stick to alphanumeric characters and underscores for simplicity and compatibility. • Length: While there is no strict limit on the length of variable names, it's recommended to keep them reasonably short and descriptive for readability.
  • 8. certain rules for naming Variables • Valid variable names: • name • age • _count • var123 • _my_var • Invalid variable names: • 1var # Cannot start with a digit • my-var # Hyphens are not allowed • my var # Spaces are not allowed • if # Reserved keyword
  • 9. Parameter shell commands, • Parameter shell commands, also known as control flow or flow control commands, are fundamental constructs in shell scripting that allow you to control the flow of execution based on conditions, loop through sets of data, and manipulate the behavior of your script. • if, while, until, for, break, continue
  • 10. if • “if-else” is dealing with two-part of the executions. If the “if-else “condition is “true” then the first group of statements will execute. If the condition is “false” then the second group of statements will execute.
  • 11. if Syntax: • The if statement starts with the keyword if. • Inside square brackets [ ], you specify the condition that needs to be evaluated. This condition can involve comparisons, logical operators, or any other expression that evaluates to true or false. • After the condition, the then keyword marks the beginning of the code block to be executed if the condition is true. • The fi keyword marks the end of the if statement. • It's important to note that spaces are required around the square brackets [ ] and after the if, then, and fi keywords for proper syntax.
  • 12. If example echo "Enter a number:" read number if [ $number -gt 0 ]; then echo "The number is positive." elif [ $number -lt 0 ]; then echo "The number is negative." else echo "The number is zero." fi
  • 13. while • The while loop in shell scripting is used to execute a block of code repeatedly as long as a specified condition is true. • The while keyword marks the beginning of the loop. • Inside square brackets [ ], you specify the condition that needs to be evaluated. • This condition can involve comparisons, logical operators, or any other expression that evaluates to true or false. • After the condition, the do keyword marks the beginning of the code block to be executed while the condition is true. • At the end of the code block, the done keyword marks the end of the loop. • It's important to note that spaces are required around the square brackets [ ] and after the while, do, and done keywords for proper syntax.
  • 14. while Example script using a while loop to count from 1 to 5 • count=1 • while [ $count -le 5 ]; do • echo "Count is $count" • count=$((count + 1)) • done Output: Count is 1 Count is 2 Count is 3 Count is 4 Count is 5
  • 15. until • The until loop in shell scripting is similar to the while loop but with an opposite condition. • It executes a block of code repeatedly until a specified condition becomes true. • The until keyword marks the beginning of the loop. • Inside square brackets [ ], you specify the condition that needs to be evaluated. • This condition can involve comparisons, logical operators, or any other expression that evaluates to true or false. • After the condition, the do keyword marks the beginning of the code block to be executed until the condition becomes true. • At the end of the code block, the done keyword marks the end of the loop. • It's important to note that spaces are required around the square brackets [ ] and after the until, do, and done keywords for proper syntax.
  • 16. until • count=1 • until [ $count -gt 5 ]; do • echo "Count is $count" • count=$((count + 1)) • done Output: Count is 1 Count is 2 Count is 3 Count is 4 Count is 5
  • 17. for • The for loop in shell scripting is used to iterate over a list of items and execute a block of code for each item in the list. • The for keyword marks the beginning of the loop. • variable is a variable that will take on each value in the list during each iteration of the loop. • list is a sequence of items separated by spaces. • After the list, the do keyword marks the beginning of the code block to be executed for each item in the list. • At the end of the code block, the done keyword marks the end of the loop. • It's important to note that spaces are required after the for, in, do, and done keywords for proper
  • 18. for • for num in 1 2 3 4 5; do • echo "Number is $num" • Done Outuput Number is 1 Number is 2 Number is 3 Number is 4 Number is 5 • The for loop iterates over the list of numbers 1 2 3 4 5. • During each iteration, the variable num takes on the value of each number in the list. • Inside the loop, it executes the code block, which prints "Number is ..." for each value of num.
  • 19. break • In shell scripting, the break statement is used to exit or terminate a loop prematurely. • It is typically used within a loop (such as for, while, or until) to stop the loop execution based on certain conditions • count=1 • while [ $count -le 10 ]; do • echo "Count is $count" • if [ $count -eq 5 ]; then • break # Exit loop if count reaches 5 • fi • count=$((count + 1)) • done OUTPUT Count is 1 Count is 2 Count is 3 Count is 4 Count is 5
  • 20. continue • In shell scripting, the continue statement is used to skip the remaining code within a loop iteration and proceed with the next iteration of the loop. • It is typically used within a loop (such as for, while, or until) to skip certain iterations based on specific conditions • for (( i=1; i<=10; i++ )); do • if [ $((i % 2)) -ne 0 ]; then • continue # Skip odd numbers • fi • echo "Number is $i" • done