SlideShare a Scribd company logo
10
Most read
11
Most read
12
Most read
Bash Case Statement
The Bash case statement is the simplest form of IF-THEN-ELSE with many ELIF
elements.
Using the case statement makes our bash script more readable and easier to maintain.
These are generally applied to simplify the complex conditions having multiple
different choices.
The Bash case statement follows a similar logic as the Javascript or C switch
statement. There is a slight difference, as follows:
The Bash case statement takes a value once and tests that value multiple times. It
stops searching for a pattern once it has found it and executed the statement linked with
it, which is almost opposite in case of the C switch statement.
Bash Case Statement Conti…
Case Statement Syntax
Patterns
A pattern and its commands make a clause, which
ends with ;;.
Patterns support special characters.
The ) terminates a pattern list.
The | operator separates multiple patterns.
case expression in
pattern_1)
statements
;;
pattern_2)
statements
;;
pattern_3|pattern_4|pattern_5)
statements
;;
pattern-n)
statements
;;
*)
statements
;;
esac
Bash Case Statement Conti…
There are some key points of bash case statements:
Each case statement in bash starts with the 'case' keyword, followed by the case
expression and 'in' keyword.
 The case statement is closed by 'esac' keyword.
We can apply multiple patterns separated by | operator. The ) operator indicates the
termination of a pattern list.
A pattern containing the statements is referred to as a clause, and it must be
terminated by double semicolon (;;).
An asterisk symbol (*) is used as a final pattern to define the default case.
 It is used as a default case when used as the last case.
Bash Case Statement Conti…
Example: #!/bin/bash
echo "Do you know Unix Operating System?"
read -p "Yes/No? :" Answer
case $Answer in
Yes|yes|y|Y)
echo "That's amazing."
echo
;;
No|no|N|n)
echo "It's easy. Let's start learning from Online Platform."
;;
esac
#!/bin/bash
echo "enter a and b"
read a
Bash Case Statement Conti…
Example:To Perform Arithmetic Operation
#!/bin/sh
echo "enter a and b"
read a
read b
echo "enter operation to be performed"
read op
case $op in
+) c=`expr $a + $b` ;;
-) c=`expr $a - $b` ;;
/) c=`expr $a / $b` ;;
*) c=`expr $a * $b` ;;
*) echo "no valid operation specified" ;;
esac
echo Result after performing operation on a and b is
echo $c
Loop
#1) Unix For loop statement
Sytax:
For varname in list
do
Echo “Statement”
done
Keywords are for, in, do, done
List is a list of variables which are separated by spaces. If list is not mentioned in the
for statement, then it takes the positional parameter value that were passed into the
shell.
Varname is any variable assumed by the user.
Example: Print table of 2. using for loop
#!/bin/sh
for num in {2..20.2}
do
Echo “Table of 2 : $num”
done
Loop
Syntax of for like C programming language.
Syntax: for (( cond1; cond2; cond3 ))
do
echo “Statement”
done
Look at the above snapshot, condition1 indicates initialization, cond2
indicates condition and cond3 indicates updation.
#!/bash/sh
For (( num=1; num<=10; num++ ))
do
echo “$num”
done
Loop
#2) while loop:
Linux scripting while loop is similar to C language while loop. There is a condition in
while. And commands are executed till the condition is valid. Once condition becomes
false, loop terminates.
Syntax: while [condition]
do
commands
done
Example: printing number in reverse order. [10 to 0]
#!/bin/sh
i=10;
while [ $i -le 0 ]
do
echo “$i”
let i-- ;
done
while infinite loop:
Loop
while infinite loop:
Infinite loop is also called endless loop. It is made with while true (it means condition
will always be true) or while : (it means an empty expression), where colon (:) is
equivalent to no operation.
Example:
#!/bash/sh
while true or while :
do
Echo “This is infinite loop. Please ctrl + c to Exit.”
done
Loop
#3) Until loop:
It is similar to while loop. The only difference is that until statement executes its code
block while its conditional expression is false, and while statement executes its code
block while its conditional expression is true.
Syntax: until [ condition ];
do
commands
done
Example: example to display number from 5 to 15.
#!/bin/sh
i=5;
Until [ $i –gt 15 ];
do
Echo “$i”
i=$(( i+1 ))
done
Command line argument
The Unix shell is used to run commands, and it allows users to pass run time
arguments to these commands.
These arguments, also known as command line parameters, that allows the users to
either control the flow of the command or to specify the input data for the command.
While running a command, the user can pass a variable number of parameters in the
command line.
Within the command script, the passed parameters are accessible using ‘positional
parameters’. These range from $0 to $9, where $0 refers to the name of the
command itself, and $1 to $9 are the first through to the ninth parameter, depending
on how many parameters were actually passed.
Example:
$ Hello student this is command line argement
Here $0 would be assigned sh
$1 would be assigned Hello
$2 would be assigned student
And so on …
We will now look at some additional commands to process these parameters.
#1) set
Command line argument
We will now look at some additional commands to process these parameters.
#1) set
This command can be used to set the values of the positional parameters on the
command line.
Example:
$ set Welcome to Unix World
$ echo $1 $2
Welcome to
Here, “Welcome” was assigned to $1 and “to” was assigned to $2 and so on.
#2) shift
This command is used to shift the position of the positional parameters. i.e. $2 will be
shifted to $1 all the way to the tenth parameter being shifted to $9. Note that if in case
there are more than 9 parameters, this mechanism can be used to read beyond the 9th.
Example:
$ set hello good morning how do you do welcome to Unix tutorial.
Here, ‘hello’ is assigned to $1, ‘good’ to $2 and so on to ‘to’ being assigned to $9. Now
the shift command can be used to shift the parameters ‘N’ places.
Command line argument
Example:
$ shift 2 $ echo $1Now $1 will be ‘morning’ and so on to $8 being ‘unix’ and $9 being
‘tutorial’.
Ad

Recommended

Unix Shell Programming subject shell scripting ppt
Unix Shell Programming subject shell scripting ppt
Radhika Ajadka
 
Unix shell scripts
Unix shell scripts
Prakash Lambha
 
Shell Programming Language in Operating System .pptx
Shell Programming Language in Operating System .pptx
SherinRappai
 
Scripting ppt
Scripting ppt
anamichintu
 
Bash
Bash
KLabCyscorpions-TechBlog
 
34-shell-programming asda asda asd asd.ppt
34-shell-programming asda asda asd asd.ppt
poyotero
 
Bash Programming
Bash Programming
Kiplangat Chelule
 
Licão 12 decision loops - statement iteration
Licão 12 decision loops - statement iteration
Acácio Oliveira
 
34-shell-programming.ppt
34-shell-programming.ppt
KiranMantri
 
Chapter 2: Introduction to Bash Scripting
Chapter 2: Introduction to Bash Scripting
azzamhadeel89
 
Osp2.pdf
Osp2.pdf
ErPawanKumar3
 
What is a shell script
What is a shell script
Dr.M.Karthika parthasarathy
 
Shell Scripting
Shell Scripting
Gaurav Shinde
 
First steps in C-Shell
First steps in C-Shell
Brahma Killampalli
 
ShellAdvanced shell scripting programm.ppt
ShellAdvanced shell scripting programm.ppt
ubaidullah75790
 
ShellProgramming and Script in operating system
ShellProgramming and Script in operating system
vinitasharma749430
 
Chap06
Chap06
Dr.Ravi
 
Scripting ppt
Scripting ppt
anamichintu
 
UNIX - Class3 - Programming Constructs
UNIX - Class3 - Programming Constructs
Nihar Ranjan Paital
 
Licão 11 decision making - statement
Licão 11 decision making - statement
Acácio Oliveira
 
AOS_Module_3ssssssssssssssssssssssssssss.pptx
AOS_Module_3ssssssssssssssssssssssssssss.pptx
rapiwip803
 
Shell Programming_Module2_Part2.pptx.pdf
Shell Programming_Module2_Part2.pptx.pdf
HIMANKMISHRA2
 
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ewout2
 
Introduction to shell
Introduction to shell
Arash Haghighat
 
Unix And Shell Scripting
Unix And Shell Scripting
Jaibeer Malik
 
003 scripting
003 scripting
Sherif Mousa
 
Mastering unix
Mastering unix
Raghu nath
 
Bash and regular expressions
Bash and regular expressions
plarsen67
 
Operating System.ppt
Operating System.ppt
Vpmv
 
Classification of Computers.pdf
Classification of Computers.pdf
Vpmv
 

More Related Content

Similar to Case, Loop & Command line args un Unix (20)

34-shell-programming.ppt
34-shell-programming.ppt
KiranMantri
 
Chapter 2: Introduction to Bash Scripting
Chapter 2: Introduction to Bash Scripting
azzamhadeel89
 
Osp2.pdf
Osp2.pdf
ErPawanKumar3
 
What is a shell script
What is a shell script
Dr.M.Karthika parthasarathy
 
Shell Scripting
Shell Scripting
Gaurav Shinde
 
First steps in C-Shell
First steps in C-Shell
Brahma Killampalli
 
ShellAdvanced shell scripting programm.ppt
ShellAdvanced shell scripting programm.ppt
ubaidullah75790
 
ShellProgramming and Script in operating system
ShellProgramming and Script in operating system
vinitasharma749430
 
Chap06
Chap06
Dr.Ravi
 
Scripting ppt
Scripting ppt
anamichintu
 
UNIX - Class3 - Programming Constructs
UNIX - Class3 - Programming Constructs
Nihar Ranjan Paital
 
Licão 11 decision making - statement
Licão 11 decision making - statement
Acácio Oliveira
 
AOS_Module_3ssssssssssssssssssssssssssss.pptx
AOS_Module_3ssssssssssssssssssssssssssss.pptx
rapiwip803
 
Shell Programming_Module2_Part2.pptx.pdf
Shell Programming_Module2_Part2.pptx.pdf
HIMANKMISHRA2
 
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ewout2
 
Introduction to shell
Introduction to shell
Arash Haghighat
 
Unix And Shell Scripting
Unix And Shell Scripting
Jaibeer Malik
 
003 scripting
003 scripting
Sherif Mousa
 
Mastering unix
Mastering unix
Raghu nath
 
Bash and regular expressions
Bash and regular expressions
plarsen67
 
34-shell-programming.ppt
34-shell-programming.ppt
KiranMantri
 
Chapter 2: Introduction to Bash Scripting
Chapter 2: Introduction to Bash Scripting
azzamhadeel89
 
ShellAdvanced shell scripting programm.ppt
ShellAdvanced shell scripting programm.ppt
ubaidullah75790
 
ShellProgramming and Script in operating system
ShellProgramming and Script in operating system
vinitasharma749430
 
UNIX - Class3 - Programming Constructs
UNIX - Class3 - Programming Constructs
Nihar Ranjan Paital
 
Licão 11 decision making - statement
Licão 11 decision making - statement
Acácio Oliveira
 
AOS_Module_3ssssssssssssssssssssssssssss.pptx
AOS_Module_3ssssssssssssssssssssssssssss.pptx
rapiwip803
 
Shell Programming_Module2_Part2.pptx.pdf
Shell Programming_Module2_Part2.pptx.pdf
HIMANKMISHRA2
 
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ewout2
 
Unix And Shell Scripting
Unix And Shell Scripting
Jaibeer Malik
 
Mastering unix
Mastering unix
Raghu nath
 
Bash and regular expressions
Bash and regular expressions
plarsen67
 

More from Vpmv (11)

Operating System.ppt
Operating System.ppt
Vpmv
 
Classification of Computers.pdf
Classification of Computers.pdf
Vpmv
 
Basic Components of Computer....pdf
Basic Components of Computer....pdf
Vpmv
 
Algorithm & Flowchart.pdf
Algorithm & Flowchart.pdf
Vpmv
 
Process & Thread Management
Process & Thread Management
Vpmv
 
Evolution or Generation of OS.pdf
Evolution or Generation of OS.pdf
Vpmv
 
Introduction of OS & Classification of Software
Introduction of OS & Classification of Software
Vpmv
 
FILE PERMISSION OR ACCESS MODE
FILE PERMISSION OR ACCESS MODE
Vpmv
 
Directory Management in Unix
Directory Management in Unix
Vpmv
 
Stucture of c program
Stucture of c program
Vpmv
 
Network topology
Network topology
Vpmv
 
Operating System.ppt
Operating System.ppt
Vpmv
 
Classification of Computers.pdf
Classification of Computers.pdf
Vpmv
 
Basic Components of Computer....pdf
Basic Components of Computer....pdf
Vpmv
 
Algorithm & Flowchart.pdf
Algorithm & Flowchart.pdf
Vpmv
 
Process & Thread Management
Process & Thread Management
Vpmv
 
Evolution or Generation of OS.pdf
Evolution or Generation of OS.pdf
Vpmv
 
Introduction of OS & Classification of Software
Introduction of OS & Classification of Software
Vpmv
 
FILE PERMISSION OR ACCESS MODE
FILE PERMISSION OR ACCESS MODE
Vpmv
 
Directory Management in Unix
Directory Management in Unix
Vpmv
 
Stucture of c program
Stucture of c program
Vpmv
 
Network topology
Network topology
Vpmv
 
Ad

Recently uploaded (20)

ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
Belicia R.S
 
Assisting Individuals and Families to Promote and Maintain Health – Unit 7 | ...
Assisting Individuals and Families to Promote and Maintain Health – Unit 7 | ...
RAKESH SAJJAN
 
Paper 107 | From Watchdog to Lapdog: Ishiguro’s Fiction and the Rise of “Godi...
Paper 107 | From Watchdog to Lapdog: Ishiguro’s Fiction and the Rise of “Godi...
Rajdeep Bavaliya
 
“THE BEST CLASS IN SCHOOL”. _
“THE BEST CLASS IN SCHOOL”. _
Colégio Santa Teresinha
 
How to Manage Inventory Movement in Odoo 18 POS
How to Manage Inventory Movement in Odoo 18 POS
Celine George
 
How to Implement Least Package Removal Strategy in Odoo 18 Inventory
How to Implement Least Package Removal Strategy in Odoo 18 Inventory
Celine George
 
Wax Moon, Richmond, VA. Terrence McPherson
Wax Moon, Richmond, VA. Terrence McPherson
TerrenceMcPherson1
 
Battle of Bookworms 2025 - U25 Literature Quiz by Pragya
Battle of Bookworms 2025 - U25 Literature Quiz by Pragya
Pragya - UEM Kolkata Quiz Club
 
Chalukyas of Gujrat, Solanki Dynasty NEP.pptx
Chalukyas of Gujrat, Solanki Dynasty NEP.pptx
Dr. Ravi Shankar Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Rajdeep Bavaliya
 
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
 
Plate Tectonic Boundaries and Continental Drift Theory
Plate Tectonic Boundaries and Continental Drift Theory
Marie
 
What are the benefits that dance brings?
What are the benefits that dance brings?
memi27
 
What is FIle and explanation of text files.pptx
What is FIle and explanation of text files.pptx
Ramakrishna Reddy Bijjam
 
ICT-8-Module-REVISED-K-10-CURRICULUM.pdf
ICT-8-Module-REVISED-K-10-CURRICULUM.pdf
penafloridaarlyn
 
BUSINESS QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 9 SEPTEMBER 2024
BUSINESS QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 9 SEPTEMBER 2024
Quiz Club of PSG College of Arts & Science
 
Paper 109 | Archetypal Journeys in ‘Interstellar’: Exploring Universal Themes...
Paper 109 | Archetypal Journeys in ‘Interstellar’: Exploring Universal Themes...
Rajdeep Bavaliya
 
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
razelitouali
 
FIRST DAY HIGH orientation for mapeh subject in grade 10.pptx
FIRST DAY HIGH orientation for mapeh subject in grade 10.pptx
GlysdiEelesor1
 
The Man In The Back – Exceptional Delaware.pdf
The Man In The Back – Exceptional Delaware.pdf
dennisongomezk
 
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
Belicia R.S
 
Assisting Individuals and Families to Promote and Maintain Health – Unit 7 | ...
Assisting Individuals and Families to Promote and Maintain Health – Unit 7 | ...
RAKESH SAJJAN
 
Paper 107 | From Watchdog to Lapdog: Ishiguro’s Fiction and the Rise of “Godi...
Paper 107 | From Watchdog to Lapdog: Ishiguro’s Fiction and the Rise of “Godi...
Rajdeep Bavaliya
 
How to Manage Inventory Movement in Odoo 18 POS
How to Manage Inventory Movement in Odoo 18 POS
Celine George
 
How to Implement Least Package Removal Strategy in Odoo 18 Inventory
How to Implement Least Package Removal Strategy in Odoo 18 Inventory
Celine George
 
Wax Moon, Richmond, VA. Terrence McPherson
Wax Moon, Richmond, VA. Terrence McPherson
TerrenceMcPherson1
 
Battle of Bookworms 2025 - U25 Literature Quiz by Pragya
Battle of Bookworms 2025 - U25 Literature Quiz by Pragya
Pragya - UEM Kolkata Quiz Club
 
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Rajdeep Bavaliya
 
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
 
Plate Tectonic Boundaries and Continental Drift Theory
Plate Tectonic Boundaries and Continental Drift Theory
Marie
 
What are the benefits that dance brings?
What are the benefits that dance brings?
memi27
 
What is FIle and explanation of text files.pptx
What is FIle and explanation of text files.pptx
Ramakrishna Reddy Bijjam
 
ICT-8-Module-REVISED-K-10-CURRICULUM.pdf
ICT-8-Module-REVISED-K-10-CURRICULUM.pdf
penafloridaarlyn
 
Paper 109 | Archetypal Journeys in ‘Interstellar’: Exploring Universal Themes...
Paper 109 | Archetypal Journeys in ‘Interstellar’: Exploring Universal Themes...
Rajdeep Bavaliya
 
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
razelitouali
 
FIRST DAY HIGH orientation for mapeh subject in grade 10.pptx
FIRST DAY HIGH orientation for mapeh subject in grade 10.pptx
GlysdiEelesor1
 
The Man In The Back – Exceptional Delaware.pdf
The Man In The Back – Exceptional Delaware.pdf
dennisongomezk
 
Ad

Case, Loop & Command line args un Unix

  • 1. Bash Case Statement The Bash case statement is the simplest form of IF-THEN-ELSE with many ELIF elements. Using the case statement makes our bash script more readable and easier to maintain. These are generally applied to simplify the complex conditions having multiple different choices. The Bash case statement follows a similar logic as the Javascript or C switch statement. There is a slight difference, as follows: The Bash case statement takes a value once and tests that value multiple times. It stops searching for a pattern once it has found it and executed the statement linked with it, which is almost opposite in case of the C switch statement.
  • 2. Bash Case Statement Conti… Case Statement Syntax Patterns A pattern and its commands make a clause, which ends with ;;. Patterns support special characters. The ) terminates a pattern list. The | operator separates multiple patterns. case expression in pattern_1) statements ;; pattern_2) statements ;; pattern_3|pattern_4|pattern_5) statements ;; pattern-n) statements ;; *) statements ;; esac
  • 3. Bash Case Statement Conti… There are some key points of bash case statements: Each case statement in bash starts with the 'case' keyword, followed by the case expression and 'in' keyword.  The case statement is closed by 'esac' keyword. We can apply multiple patterns separated by | operator. The ) operator indicates the termination of a pattern list. A pattern containing the statements is referred to as a clause, and it must be terminated by double semicolon (;;). An asterisk symbol (*) is used as a final pattern to define the default case.  It is used as a default case when used as the last case.
  • 4. Bash Case Statement Conti… Example: #!/bin/bash echo "Do you know Unix Operating System?" read -p "Yes/No? :" Answer case $Answer in Yes|yes|y|Y) echo "That's amazing." echo ;; No|no|N|n) echo "It's easy. Let's start learning from Online Platform." ;; esac #!/bin/bash echo "enter a and b" read a
  • 5. Bash Case Statement Conti… Example:To Perform Arithmetic Operation #!/bin/sh echo "enter a and b" read a read b echo "enter operation to be performed" read op case $op in +) c=`expr $a + $b` ;; -) c=`expr $a - $b` ;; /) c=`expr $a / $b` ;; *) c=`expr $a * $b` ;; *) echo "no valid operation specified" ;; esac echo Result after performing operation on a and b is echo $c
  • 6. Loop #1) Unix For loop statement Sytax: For varname in list do Echo “Statement” done Keywords are for, in, do, done List is a list of variables which are separated by spaces. If list is not mentioned in the for statement, then it takes the positional parameter value that were passed into the shell. Varname is any variable assumed by the user. Example: Print table of 2. using for loop #!/bin/sh for num in {2..20.2} do Echo “Table of 2 : $num” done
  • 7. Loop Syntax of for like C programming language. Syntax: for (( cond1; cond2; cond3 )) do echo “Statement” done Look at the above snapshot, condition1 indicates initialization, cond2 indicates condition and cond3 indicates updation. #!/bash/sh For (( num=1; num<=10; num++ )) do echo “$num” done
  • 8. Loop #2) while loop: Linux scripting while loop is similar to C language while loop. There is a condition in while. And commands are executed till the condition is valid. Once condition becomes false, loop terminates. Syntax: while [condition] do commands done Example: printing number in reverse order. [10 to 0] #!/bin/sh i=10; while [ $i -le 0 ] do echo “$i” let i-- ; done while infinite loop:
  • 9. Loop while infinite loop: Infinite loop is also called endless loop. It is made with while true (it means condition will always be true) or while : (it means an empty expression), where colon (:) is equivalent to no operation. Example: #!/bash/sh while true or while : do Echo “This is infinite loop. Please ctrl + c to Exit.” done
  • 10. Loop #3) Until loop: It is similar to while loop. The only difference is that until statement executes its code block while its conditional expression is false, and while statement executes its code block while its conditional expression is true. Syntax: until [ condition ]; do commands done Example: example to display number from 5 to 15. #!/bin/sh i=5; Until [ $i –gt 15 ]; do Echo “$i” i=$(( i+1 )) done
  • 11. Command line argument The Unix shell is used to run commands, and it allows users to pass run time arguments to these commands. These arguments, also known as command line parameters, that allows the users to either control the flow of the command or to specify the input data for the command. While running a command, the user can pass a variable number of parameters in the command line. Within the command script, the passed parameters are accessible using ‘positional parameters’. These range from $0 to $9, where $0 refers to the name of the command itself, and $1 to $9 are the first through to the ninth parameter, depending on how many parameters were actually passed. Example: $ Hello student this is command line argement Here $0 would be assigned sh $1 would be assigned Hello $2 would be assigned student And so on … We will now look at some additional commands to process these parameters. #1) set
  • 12. Command line argument We will now look at some additional commands to process these parameters. #1) set This command can be used to set the values of the positional parameters on the command line. Example: $ set Welcome to Unix World $ echo $1 $2 Welcome to Here, “Welcome” was assigned to $1 and “to” was assigned to $2 and so on. #2) shift This command is used to shift the position of the positional parameters. i.e. $2 will be shifted to $1 all the way to the tenth parameter being shifted to $9. Note that if in case there are more than 9 parameters, this mechanism can be used to read beyond the 9th. Example: $ set hello good morning how do you do welcome to Unix tutorial. Here, ‘hello’ is assigned to $1, ‘good’ to $2 and so on to ‘to’ being assigned to $9. Now the shift command can be used to shift the parameters ‘N’ places.
  • 13. Command line argument Example: $ shift 2 $ echo $1Now $1 will be ‘morning’ and so on to $8 being ‘unix’ and $9 being ‘tutorial’.