SlideShare a Scribd company logo
Submitted by: Gaurav Bisht
B.Tech (CSE) 6th Sem
Contents:
 What is Shell?
 Brief introduction to Shell Programming
 What are Shell Variables?
 Some Simple Shell Programs
 Wildcards
What is Shell?
 A shell is a computer program which works as the interface to
access the services provided by an OS.
 A shell is a command-line interpreter.
 It performs operations such as file manipulation, program
execution and printing text.
Introduction to Shell Programming:
 Shell programming is a computer program designed to be run by UNIX/ LINUX shell.
 We write shell scripts to avoid repetitive work and automation.
 A shell script comprises of Shell Keywords, Shell Variables, Shell Commands, functions and
Control Flow Statements.
 Shell script is saved with ’.sh’ file extension for example ’myscript.sh’.
Shell Variables:
 A variable is a character string to which we assign a value.
 The value assigned could be a number, text, filename, device, or any other type of data.
 The shell enables you to create, assign, and delete variables.
 Variables have naming convention such as the name of a variable can contain only letters (a to z or A
to Z), numbers ( 0 to 9) or the underscore character ( _).
‘_VAR’ ‘TOKEN_A’ ‘VAR_1’ ‘VAR_2’ These are valid variable names.
‘2_VAR’ ‘-VARIABLE’ ‘VAR1-VAR2’ ‘VAR_A!’ These are invalid variable names.
Shell Variables (Cont.):
 Defining Variables:
SYNTAX – For example –
variable_name = variable_value; NAME = “Gaurav Bisht”
ROLLNO = 7
 Accessing Variables:
INPUT – OUTPUT –
NAME = “Gaurav Bisht” Gaurav Bisht
echo $NAME
Shell Variables (Cont.):
 Variables in shell do not use special characters like ‘!’, ‘#’, ‘?’ or ‘$’ since there exists predefined
special variables in shell scripting.
S. No. Special
Variable
Description Input Output
1. $0 Display file name of current script echo “File Name: $0” File Name: ./test.sh
2. $# Display number of arguments
supported to a script
echo “Total no. of
parameters: $#”
Total no. of parameters: 2
3. $? The exit status of the last command
executed
echo $? 0
4. $$ The process number or the Process ID
(PID) of the current shell
echo $$ 29949
5. $! The process number of the last
background command
echo $! 1342
Some Simple Shell Programs:
 Program 1 – Adding 2 numbers.
echo "Enter first number:"
read x
echo "Enter second number:"
read y
sum=x+y
echo "The result of addition =$sum"
Some Simple Shell Programs (Cont.):
 Program 2 – Concatenation of 2 strings.
str1=“Hello”
str2=“World”
str3=“$str1 $str2”
echo $str3
Some Simple Shell Programs (Cont.):
 Program 3 – Comparison of 2 strings.
read -p "Enter first string: " VAR1
read -p "Enter second string: " VAR2
if [[ "$VAR1" == "$VAR2" ]]
then
echo "Strings are equal."
else
echo "Strings are not equal."
fi
Some Simple Shell Programs (Cont.):
 Program 4 – Maximum of 3 numbers.
echo " Enter A value: "
read a
echo " Enter B value: "
read b
echo " Enter C value: "
read c
if [ $a -gt $b ] && [ $a -gt $c ]
then
echo "A value is greater"
elif [ $b -gt $a ] && [ $b -gt $c ]
then
echo "B value is greatest "
else
echo "C value is greatest "
fi
Wildcards:
 A wildcard is a character that can be used as a substitute for any of a class of characters in a
search, thereby greatly increasing the flexibility and efficiency of searches.
 There are 3 types of wildcards:
1. Star Wildcard (*)
2. Question mark Wildcard (?)
3. Square Bracket Wildcard ([])
Wildcards (Cont.):
 Star Wildcard –
- It is most frequently used and most useful wildcard in shell programming.
- The star wildcard has the broadest meaning of any of the wildcards, as it can represent zero
characters, all single characters or any string.
For example –
- file * => It will display all the files present in the directory along with their type.
- ls *.txt => It will list all the files with extension ‘.txt’.
Wildcards (Cont.):
 Question mark Wildcard –
- The question mark wildcard is used to represent exactly one character, which can be any
single character.
- Two question marks in succession would represent any two characters .
- Three question marks in succession would represent any string consisting of three
characters.
For example –
- file ??? => It will display data in the present directory whose name is exactly 3 characters in length
irrespective if the extension.
- file ? ?? ??? => It will display data on all objects whose names are one, two or three characters in
length
Wildcards (Cont.):
 Square Bracket Wildcard –
- The square bracket wildcard is used to represent any of the characters enclosed in the
square brackets.
For example –
- file *[xyz]* => It will display information about all objects in the current directory that have an x, y or z
in them.
- ls *.[xyz]* => It will list all files that had an extension that begins with x, y or z.
Wildcards, Simple Shell Programs and Shell Variables

More Related Content

What's hot

The Linux Kernel Implementation of Pipes and FIFOs
The Linux Kernel Implementation of Pipes and FIFOsThe Linux Kernel Implementation of Pipes and FIFOs
The Linux Kernel Implementation of Pipes and FIFOsDivye Kapoor
 
A Quick Introduction to Linux
A Quick Introduction to LinuxA Quick Introduction to Linux
A Quick Introduction to LinuxTusharadri Sarkar
 
CRYPTOGRAPHY AND NETWORK SECURITY
CRYPTOGRAPHY AND NETWORK SECURITYCRYPTOGRAPHY AND NETWORK SECURITY
CRYPTOGRAPHY AND NETWORK SECURITYKathirvel Ayyaswamy
 
Advanced computer network
Advanced computer networkAdvanced computer network
Advanced computer networkTrinity Dwarka
 
Message authentication
Message authenticationMessage authentication
Message authenticationCAS
 
Git, CMake, Conan - How to ship and reuse our C++ projects?
Git, CMake, Conan - How to ship and reuse our C++ projects?Git, CMake, Conan - How to ship and reuse our C++ projects?
Git, CMake, Conan - How to ship and reuse our C++ projects?Mateusz Pusz
 
Overview of computing paradigm
Overview of computing paradigmOverview of computing paradigm
Overview of computing paradigmRipal Ranpara
 
Linux kernel debugging
Linux kernel debuggingLinux kernel debugging
Linux kernel debugginglibfetion
 
Communication primitives
Communication primitivesCommunication primitives
Communication primitivesStudent
 
Subnetting (FLSM & VLSM) with examples
Subnetting (FLSM & VLSM) with examplesSubnetting (FLSM & VLSM) with examples
Subnetting (FLSM & VLSM) with examplesKrishna Mohan
 
Internetworking fundamentals(networking)
Internetworking fundamentals(networking)Internetworking fundamentals(networking)
Internetworking fundamentals(networking)welcometofacebook
 
Chapter 5 : Link Layer
Chapter 5 : Link LayerChapter 5 : Link Layer
Chapter 5 : Link LayerAmin Omi
 
BeagleBone black
BeagleBone blackBeagleBone black
BeagleBone blackRaja Vedula
 
CS6701 CRYPTOGRAPHY AND NETWORK SECURITY
CS6701 CRYPTOGRAPHY AND NETWORK SECURITYCS6701 CRYPTOGRAPHY AND NETWORK SECURITY
CS6701 CRYPTOGRAPHY AND NETWORK SECURITYKathirvel Ayyaswamy
 
IP addressing seminar ppt
IP addressing seminar pptIP addressing seminar ppt
IP addressing seminar pptSmriti Rastogi
 

What's hot (20)

The Linux Kernel Implementation of Pipes and FIFOs
The Linux Kernel Implementation of Pipes and FIFOsThe Linux Kernel Implementation of Pipes and FIFOs
The Linux Kernel Implementation of Pipes and FIFOs
 
A Quick Introduction to Linux
A Quick Introduction to LinuxA Quick Introduction to Linux
A Quick Introduction to Linux
 
CRYPTOGRAPHY AND NETWORK SECURITY
CRYPTOGRAPHY AND NETWORK SECURITYCRYPTOGRAPHY AND NETWORK SECURITY
CRYPTOGRAPHY AND NETWORK SECURITY
 
Cn ipv4 addressing
Cn ipv4 addressingCn ipv4 addressing
Cn ipv4 addressing
 
Advanced computer network
Advanced computer networkAdvanced computer network
Advanced computer network
 
Message authentication
Message authenticationMessage authentication
Message authentication
 
IPv4 Addressing
 IPv4 Addressing   IPv4 Addressing
IPv4 Addressing
 
Git, CMake, Conan - How to ship and reuse our C++ projects?
Git, CMake, Conan - How to ship and reuse our C++ projects?Git, CMake, Conan - How to ship and reuse our C++ projects?
Git, CMake, Conan - How to ship and reuse our C++ projects?
 
Sha3
Sha3Sha3
Sha3
 
Overview of computing paradigm
Overview of computing paradigmOverview of computing paradigm
Overview of computing paradigm
 
Linux kernel debugging
Linux kernel debuggingLinux kernel debugging
Linux kernel debugging
 
Communication primitives
Communication primitivesCommunication primitives
Communication primitives
 
Subnetting (FLSM & VLSM) with examples
Subnetting (FLSM & VLSM) with examplesSubnetting (FLSM & VLSM) with examples
Subnetting (FLSM & VLSM) with examples
 
Internetworking fundamentals(networking)
Internetworking fundamentals(networking)Internetworking fundamentals(networking)
Internetworking fundamentals(networking)
 
Chapter 5 : Link Layer
Chapter 5 : Link LayerChapter 5 : Link Layer
Chapter 5 : Link Layer
 
strong slot and filler
strong slot and fillerstrong slot and filler
strong slot and filler
 
Regular Expressions To Finite Automata
Regular Expressions To Finite AutomataRegular Expressions To Finite Automata
Regular Expressions To Finite Automata
 
BeagleBone black
BeagleBone blackBeagleBone black
BeagleBone black
 
CS6701 CRYPTOGRAPHY AND NETWORK SECURITY
CS6701 CRYPTOGRAPHY AND NETWORK SECURITYCS6701 CRYPTOGRAPHY AND NETWORK SECURITY
CS6701 CRYPTOGRAPHY AND NETWORK SECURITY
 
IP addressing seminar ppt
IP addressing seminar pptIP addressing seminar ppt
IP addressing seminar ppt
 

Similar to Wildcards, Simple Shell Programs and Shell Variables

Using Unix
Using UnixUsing Unix
Using UnixDr.Ravi
 
Unix And Shell Scripting
Unix And Shell ScriptingUnix And Shell Scripting
Unix And Shell ScriptingJaibeer Malik
 
Shell-Scripting-1.pdf
Shell-Scripting-1.pdfShell-Scripting-1.pdf
Shell-Scripting-1.pdfaznabi
 
intro unix/linux 03
intro unix/linux 03intro unix/linux 03
intro unix/linux 03duquoi
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell ScriptingRaghu nath
 
Commands and shell programming (3)
Commands and shell programming (3)Commands and shell programming (3)
Commands and shell programming (3)christ university
 
Complete Guide for Linux shell programming
Complete Guide for Linux shell programmingComplete Guide for Linux shell programming
Complete Guide for Linux shell programmingsudhir singh yadav
 
Shell Scripting and Programming.pptx
Shell Scripting and Programming.pptxShell Scripting and Programming.pptx
Shell Scripting and Programming.pptxHarsha Patel
 
Shell Scripting and Programming.pptx
Shell Scripting and Programming.pptxShell Scripting and Programming.pptx
Shell Scripting and Programming.pptxHarsha Patel
 
Lex tool manual
Lex tool manualLex tool manual
Lex tool manualSami Said
 
intro unix/linux 02
intro unix/linux 02intro unix/linux 02
intro unix/linux 02duquoi
 

Similar to Wildcards, Simple Shell Programs and Shell Variables (20)

Using Unix
Using UnixUsing Unix
Using Unix
 
Unix And Shell Scripting
Unix And Shell ScriptingUnix And Shell Scripting
Unix And Shell Scripting
 
part2.pdf
part2.pdfpart2.pdf
part2.pdf
 
Unix
UnixUnix
Unix
 
Shellscripting
ShellscriptingShellscripting
Shellscripting
 
SHELL PROGRAMMING
SHELL PROGRAMMINGSHELL PROGRAMMING
SHELL PROGRAMMING
 
Shell-Scripting-1.pdf
Shell-Scripting-1.pdfShell-Scripting-1.pdf
Shell-Scripting-1.pdf
 
Shell programming
Shell programmingShell programming
Shell programming
 
intro unix/linux 03
intro unix/linux 03intro unix/linux 03
intro unix/linux 03
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell Scripting
 
Unix lab
Unix labUnix lab
Unix lab
 
Spsl by sasidhar 3 unit
Spsl by sasidhar  3 unitSpsl by sasidhar  3 unit
Spsl by sasidhar 3 unit
 
Commands and shell programming (3)
Commands and shell programming (3)Commands and shell programming (3)
Commands and shell programming (3)
 
Basics of shell programming
Basics of shell programmingBasics of shell programming
Basics of shell programming
 
Basics of shell programming
Basics of shell programmingBasics of shell programming
Basics of shell programming
 
Complete Guide for Linux shell programming
Complete Guide for Linux shell programmingComplete Guide for Linux shell programming
Complete Guide for Linux shell programming
 
Shell Scripting and Programming.pptx
Shell Scripting and Programming.pptxShell Scripting and Programming.pptx
Shell Scripting and Programming.pptx
 
Shell Scripting and Programming.pptx
Shell Scripting and Programming.pptxShell Scripting and Programming.pptx
Shell Scripting and Programming.pptx
 
Lex tool manual
Lex tool manualLex tool manual
Lex tool manual
 
intro unix/linux 02
intro unix/linux 02intro unix/linux 02
intro unix/linux 02
 

Recently uploaded

Fruit shop management system project report.pdf
Fruit shop management system project report.pdfFruit shop management system project report.pdf
Fruit shop management system project report.pdfKamal Acharya
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdffxintegritypublishin
 
Scaling in conventional MOSFET for constant electric field and constant voltage
Scaling in conventional MOSFET for constant electric field and constant voltageScaling in conventional MOSFET for constant electric field and constant voltage
Scaling in conventional MOSFET for constant electric field and constant voltageRCC Institute of Information Technology
 
Online resume builder management system project report.pdf
Online resume builder management system project report.pdfOnline resume builder management system project report.pdf
Online resume builder management system project report.pdfKamal Acharya
 
Event Management System Vb Net Project Report.pdf
Event Management System Vb Net  Project Report.pdfEvent Management System Vb Net  Project Report.pdf
Event Management System Vb Net Project Report.pdfKamal Acharya
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Electivekarthi keyan
 
shape functions of 1D and 2 D rectangular elements.pptx
shape functions of 1D and 2 D rectangular elements.pptxshape functions of 1D and 2 D rectangular elements.pptx
shape functions of 1D and 2 D rectangular elements.pptxVishalDeshpande27
 
Hall booking system project report .pdf
Hall booking system project report  .pdfHall booking system project report  .pdf
Hall booking system project report .pdfKamal Acharya
 
Top 13 Famous Civil Engineering Scientist
Top 13 Famous Civil Engineering ScientistTop 13 Famous Civil Engineering Scientist
Top 13 Famous Civil Engineering Scientistgettygaming1
 
Automobile Management System Project Report.pdf
Automobile Management System Project Report.pdfAutomobile Management System Project Report.pdf
Automobile Management System Project Report.pdfKamal Acharya
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdfKamal Acharya
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdfKamal Acharya
 
Natalia Rutkowska - BIM School Course in Kraków
Natalia Rutkowska - BIM School Course in KrakówNatalia Rutkowska - BIM School Course in Kraków
Natalia Rutkowska - BIM School Course in Krakówbim.edu.pl
 
A case study of cinema management system project report..pdf
A case study of cinema management system project report..pdfA case study of cinema management system project report..pdf
A case study of cinema management system project report..pdfKamal Acharya
 
Online blood donation management system project.pdf
Online blood donation management system project.pdfOnline blood donation management system project.pdf
Online blood donation management system project.pdfKamal Acharya
 
Danfoss NeoCharge Technology -A Revolution in 2024.pdf
Danfoss NeoCharge Technology -A Revolution in 2024.pdfDanfoss NeoCharge Technology -A Revolution in 2024.pdf
Danfoss NeoCharge Technology -A Revolution in 2024.pdfNurvisNavarroSanchez
 
LIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.pptLIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.pptssuser9bd3ba
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfPipe Restoration Solutions
 
Introduction to Casting Processes in Manufacturing
Introduction to Casting Processes in ManufacturingIntroduction to Casting Processes in Manufacturing
Introduction to Casting Processes in Manufacturingssuser0811ec
 
Antenna efficency lecture course chapter 3.pdf
Antenna  efficency lecture course chapter 3.pdfAntenna  efficency lecture course chapter 3.pdf
Antenna efficency lecture course chapter 3.pdfAbrahamGadissa
 

Recently uploaded (20)

Fruit shop management system project report.pdf
Fruit shop management system project report.pdfFruit shop management system project report.pdf
Fruit shop management system project report.pdf
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 
Scaling in conventional MOSFET for constant electric field and constant voltage
Scaling in conventional MOSFET for constant electric field and constant voltageScaling in conventional MOSFET for constant electric field and constant voltage
Scaling in conventional MOSFET for constant electric field and constant voltage
 
Online resume builder management system project report.pdf
Online resume builder management system project report.pdfOnline resume builder management system project report.pdf
Online resume builder management system project report.pdf
 
Event Management System Vb Net Project Report.pdf
Event Management System Vb Net  Project Report.pdfEvent Management System Vb Net  Project Report.pdf
Event Management System Vb Net Project Report.pdf
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
shape functions of 1D and 2 D rectangular elements.pptx
shape functions of 1D and 2 D rectangular elements.pptxshape functions of 1D and 2 D rectangular elements.pptx
shape functions of 1D and 2 D rectangular elements.pptx
 
Hall booking system project report .pdf
Hall booking system project report  .pdfHall booking system project report  .pdf
Hall booking system project report .pdf
 
Top 13 Famous Civil Engineering Scientist
Top 13 Famous Civil Engineering ScientistTop 13 Famous Civil Engineering Scientist
Top 13 Famous Civil Engineering Scientist
 
Automobile Management System Project Report.pdf
Automobile Management System Project Report.pdfAutomobile Management System Project Report.pdf
Automobile Management System Project Report.pdf
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
Natalia Rutkowska - BIM School Course in Kraków
Natalia Rutkowska - BIM School Course in KrakówNatalia Rutkowska - BIM School Course in Kraków
Natalia Rutkowska - BIM School Course in Kraków
 
A case study of cinema management system project report..pdf
A case study of cinema management system project report..pdfA case study of cinema management system project report..pdf
A case study of cinema management system project report..pdf
 
Online blood donation management system project.pdf
Online blood donation management system project.pdfOnline blood donation management system project.pdf
Online blood donation management system project.pdf
 
Danfoss NeoCharge Technology -A Revolution in 2024.pdf
Danfoss NeoCharge Technology -A Revolution in 2024.pdfDanfoss NeoCharge Technology -A Revolution in 2024.pdf
Danfoss NeoCharge Technology -A Revolution in 2024.pdf
 
LIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.pptLIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.ppt
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
Introduction to Casting Processes in Manufacturing
Introduction to Casting Processes in ManufacturingIntroduction to Casting Processes in Manufacturing
Introduction to Casting Processes in Manufacturing
 
Antenna efficency lecture course chapter 3.pdf
Antenna  efficency lecture course chapter 3.pdfAntenna  efficency lecture course chapter 3.pdf
Antenna efficency lecture course chapter 3.pdf
 

Wildcards, Simple Shell Programs and Shell Variables

  • 1. Submitted by: Gaurav Bisht B.Tech (CSE) 6th Sem
  • 2. Contents:  What is Shell?  Brief introduction to Shell Programming  What are Shell Variables?  Some Simple Shell Programs  Wildcards
  • 3. What is Shell?  A shell is a computer program which works as the interface to access the services provided by an OS.  A shell is a command-line interpreter.  It performs operations such as file manipulation, program execution and printing text.
  • 4. Introduction to Shell Programming:  Shell programming is a computer program designed to be run by UNIX/ LINUX shell.  We write shell scripts to avoid repetitive work and automation.  A shell script comprises of Shell Keywords, Shell Variables, Shell Commands, functions and Control Flow Statements.  Shell script is saved with ’.sh’ file extension for example ’myscript.sh’.
  • 5. Shell Variables:  A variable is a character string to which we assign a value.  The value assigned could be a number, text, filename, device, or any other type of data.  The shell enables you to create, assign, and delete variables.  Variables have naming convention such as the name of a variable can contain only letters (a to z or A to Z), numbers ( 0 to 9) or the underscore character ( _). ‘_VAR’ ‘TOKEN_A’ ‘VAR_1’ ‘VAR_2’ These are valid variable names. ‘2_VAR’ ‘-VARIABLE’ ‘VAR1-VAR2’ ‘VAR_A!’ These are invalid variable names.
  • 6. Shell Variables (Cont.):  Defining Variables: SYNTAX – For example – variable_name = variable_value; NAME = “Gaurav Bisht” ROLLNO = 7  Accessing Variables: INPUT – OUTPUT – NAME = “Gaurav Bisht” Gaurav Bisht echo $NAME
  • 7. Shell Variables (Cont.):  Variables in shell do not use special characters like ‘!’, ‘#’, ‘?’ or ‘$’ since there exists predefined special variables in shell scripting. S. No. Special Variable Description Input Output 1. $0 Display file name of current script echo “File Name: $0” File Name: ./test.sh 2. $# Display number of arguments supported to a script echo “Total no. of parameters: $#” Total no. of parameters: 2 3. $? The exit status of the last command executed echo $? 0 4. $$ The process number or the Process ID (PID) of the current shell echo $$ 29949 5. $! The process number of the last background command echo $! 1342
  • 8. Some Simple Shell Programs:  Program 1 – Adding 2 numbers. echo "Enter first number:" read x echo "Enter second number:" read y sum=x+y echo "The result of addition =$sum"
  • 9. Some Simple Shell Programs (Cont.):  Program 2 – Concatenation of 2 strings. str1=“Hello” str2=“World” str3=“$str1 $str2” echo $str3
  • 10. Some Simple Shell Programs (Cont.):  Program 3 – Comparison of 2 strings. read -p "Enter first string: " VAR1 read -p "Enter second string: " VAR2 if [[ "$VAR1" == "$VAR2" ]] then echo "Strings are equal." else echo "Strings are not equal." fi
  • 11. Some Simple Shell Programs (Cont.):  Program 4 – Maximum of 3 numbers. echo " Enter A value: " read a echo " Enter B value: " read b echo " Enter C value: " read c if [ $a -gt $b ] && [ $a -gt $c ] then echo "A value is greater" elif [ $b -gt $a ] && [ $b -gt $c ] then echo "B value is greatest " else echo "C value is greatest " fi
  • 12. Wildcards:  A wildcard is a character that can be used as a substitute for any of a class of characters in a search, thereby greatly increasing the flexibility and efficiency of searches.  There are 3 types of wildcards: 1. Star Wildcard (*) 2. Question mark Wildcard (?) 3. Square Bracket Wildcard ([])
  • 13. Wildcards (Cont.):  Star Wildcard – - It is most frequently used and most useful wildcard in shell programming. - The star wildcard has the broadest meaning of any of the wildcards, as it can represent zero characters, all single characters or any string. For example – - file * => It will display all the files present in the directory along with their type. - ls *.txt => It will list all the files with extension ‘.txt’.
  • 14. Wildcards (Cont.):  Question mark Wildcard – - The question mark wildcard is used to represent exactly one character, which can be any single character. - Two question marks in succession would represent any two characters . - Three question marks in succession would represent any string consisting of three characters. For example – - file ??? => It will display data in the present directory whose name is exactly 3 characters in length irrespective if the extension. - file ? ?? ??? => It will display data on all objects whose names are one, two or three characters in length
  • 15. Wildcards (Cont.):  Square Bracket Wildcard – - The square bracket wildcard is used to represent any of the characters enclosed in the square brackets. For example – - file *[xyz]* => It will display information about all objects in the current directory that have an x, y or z in them. - ls *.[xyz]* => It will list all files that had an extension that begins with x, y or z.