SlideShare a Scribd company logo
Presentation on
 Looping Conditions and
Command Line Arguments
Conditional loop
• conditional loop is a way for computer
  programs to repeat one or more various
  steps depending on conditions set either
  by the programmer initially or real-time
  by the actual program.
• Basically a loop has a conditional
  statement or a command and body of that
  loop which has some list of commands or
  statements to be executed repeatedly.
While Loop
• The while loop is used to execute a set of
  commands repeatedly until some
  condition occurs.
• It is usually used when the value of a
  variable has to be manipulated repeatedly.
Basic syntax

While command
do
    list
done

It can also be written as,

While command ; do list ; done
Steps to execute a while loop
1. Execute command.
2. If the exit status of command is nonzero,
   exit from the while loop
3. If the exit status of command is zero,
   execute list.
4. When list finishes execution, return to
   step 1.
For example,
                              The output looks like,
x=0                           0
while [ $x –lt 10 ]           1
do                            2
    echo $x                   3
     x=`echo “$x + 1” | bc`   4
done                          5
                              6
                              7
                              8
                              9
Example(2)
c=1                     Output,
while [ $c -le 5 ]      Welcome 1 times
 do                     Welcome 2 times
    echo "Welcome $c    Welcome 3 times
  times"                Welcome 4 times
    (( c++ ))           Welcome 5 times
 done
Nested while loop

• It is a loop in which a while loop will be a
  part of the body of another while loop.
• There is no restrictions for the number of
  nested while loops.
• But it will b better to avoid more than 5
  nested loops.
Syntax is,
while command1 ; # this is loop1, the outer loop
do
    list1
    while command2 ; # this is loop2, the inner
  loop
      do
          list2
      done
      list3
done
Example,

x=0
while [ "$x" -lt 10 ] ; # this is loop1
 do
    y="$x"
    while [ "$y" -ge 0 ] ; # this is loop2
     do
         echo "$y c"
         y=´echo "$y - 1" | bc´
     done
     echo
     x=´echo "$x + 1" | bc´
 done
The output will be,

0
10
210
3210
43210
543210
6543210
76543210
876543210
9876543210
For loop


• The for loop is used to execute a set of
  commands repeatedly for each item in a
  list.
• One of its most common uses is in
  performing the same set of commands for
  a large number of files.
The common syntax is,
for name in word1 word2 ... wordN
  do
     list
  done

It can also be written as,

for name in word1 word2 ... wordN ; do list ; done
For a simple for loop,

for i in 0 1 2 3 4 5 6 7 8 9   The output is,
 do                            0
    echo $i                    1
 done                          2
                               3
                               4
                               5
                               6
                               7
                               8
                               9
another example,

for i in `cat 1.txt`     Output is,
 do
     echo $i             F
  done                   S
                         T
The contents in 1.txt,
F
S
T
Example(3)
alphabet="a b c d e"          Output,
count=0                       a
for letter in $alphabet
                              b
 do
  count=`expr $count + 1`     c
  echo "Letter $count is      d
  [$letter]"                  e
 done
Command line arguments
• The arguments used to pass to the shell
  scripts while interpreting are called
  command line arguments.
• $0 indicates the name of the script.
• $1 indicates the 1st argument of that script.
• $2 indicates the 2nd argument.
• $$ used to denote the process ID.
• $# used to count the number of arguments.
• $@ denotes all arguments.
A simple example,

var1=$1
var2=$2
var3=` expr $var1 + $var2 `
echo $var3

 chmod +x file.sh
./file.sh 2 3

Output,
5
Using argument status,
var1=$1               chmod +x file1.sh
var2=$2              ./file1.sh 2 3
var3=`expr $var1 +    output,
  $var2`             5
if [$# -ne 2 ]
then                 ./file1.sh 2 3 4
echo “no”            Output,
exit 1               no
else
echo $var3
fi
Any Queries????
Thank You

More Related Content

What's hot

Let's golang
Let's golangLet's golang
Let's golang
SuHyun Jeon
 
Sol8
Sol8Sol8
Scripting 101
Scripting 101Scripting 101
Scripting 101
ohardebol
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest UpdatesIftekhar Eather
 
ZeroMQ Is The Answer: DPC 11 Version
ZeroMQ Is The Answer: DPC 11 VersionZeroMQ Is The Answer: DPC 11 Version
ZeroMQ Is The Answer: DPC 11 Version
Ian Barber
 
ZeroMQ Is The Answer
ZeroMQ Is The AnswerZeroMQ Is The Answer
ZeroMQ Is The Answer
Ian Barber
 
Bag of tricks
Bag of tricksBag of tricks
Bag of tricks
brian d foy
 
Cis 216 – shell scripting
Cis 216 – shell scriptingCis 216 – shell scripting
Cis 216 – shell scripting
Dan Morrill
 
Process monitoring in UNIX shell scripting
Process monitoring in UNIX shell scriptingProcess monitoring in UNIX shell scripting
Process monitoring in UNIX shell scripting
Dan Morrill
 
Perl Bag of Tricks - Baltimore Perl mongers
Perl Bag of Tricks  -  Baltimore Perl mongersPerl Bag of Tricks  -  Baltimore Perl mongers
Perl Bag of Tricks - Baltimore Perl mongers
brian d foy
 
The Magic Of Tie
The Magic Of TieThe Magic Of Tie
The Magic Of Tie
brian d foy
 
Shell实现的windows回收站功能的脚本
Shell实现的windows回收站功能的脚本Shell实现的windows回收站功能的脚本
Shell实现的windows回收站功能的脚本
Lingfei Kong
 
Generating Power with Yield
Generating Power with YieldGenerating Power with Yield
Generating Power with Yield
Jason Myers
 
Redis & ZeroMQ: How to scale your application
Redis & ZeroMQ: How to scale your applicationRedis & ZeroMQ: How to scale your application
Redis & ZeroMQ: How to scale your application
rjsmelo
 
Tugas Program C++
Tugas Program C++Tugas Program C++
Tugas Program C++
Reynes E. Tekay
 
ZeroMQ: Messaging Made Simple
ZeroMQ: Messaging Made SimpleZeroMQ: Messaging Made Simple
ZeroMQ: Messaging Made Simple
Ian Barber
 
What's new in PHP 5.5
What's new in PHP 5.5What's new in PHP 5.5
What's new in PHP 5.5Tom Corrigan
 
[2019] 아직도 돈 주고 DB 쓰나요? for Developer
[2019] 아직도 돈 주고 DB 쓰나요? for Developer[2019] 아직도 돈 주고 DB 쓰나요? for Developer
[2019] 아직도 돈 주고 DB 쓰나요? for Developer
NHN FORWARD
 
Advanced modulinos
Advanced modulinosAdvanced modulinos
Advanced modulinosbrian d foy
 
Symfony messenger - PHPers Summit 2019
Symfony messenger - PHPers Summit 2019Symfony messenger - PHPers Summit 2019
Symfony messenger - PHPers Summit 2019
Michał Kurzeja
 

What's hot (20)

Let's golang
Let's golangLet's golang
Let's golang
 
Sol8
Sol8Sol8
Sol8
 
Scripting 101
Scripting 101Scripting 101
Scripting 101
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest Updates
 
ZeroMQ Is The Answer: DPC 11 Version
ZeroMQ Is The Answer: DPC 11 VersionZeroMQ Is The Answer: DPC 11 Version
ZeroMQ Is The Answer: DPC 11 Version
 
ZeroMQ Is The Answer
ZeroMQ Is The AnswerZeroMQ Is The Answer
ZeroMQ Is The Answer
 
Bag of tricks
Bag of tricksBag of tricks
Bag of tricks
 
Cis 216 – shell scripting
Cis 216 – shell scriptingCis 216 – shell scripting
Cis 216 – shell scripting
 
Process monitoring in UNIX shell scripting
Process monitoring in UNIX shell scriptingProcess monitoring in UNIX shell scripting
Process monitoring in UNIX shell scripting
 
Perl Bag of Tricks - Baltimore Perl mongers
Perl Bag of Tricks  -  Baltimore Perl mongersPerl Bag of Tricks  -  Baltimore Perl mongers
Perl Bag of Tricks - Baltimore Perl mongers
 
The Magic Of Tie
The Magic Of TieThe Magic Of Tie
The Magic Of Tie
 
Shell实现的windows回收站功能的脚本
Shell实现的windows回收站功能的脚本Shell实现的windows回收站功能的脚本
Shell实现的windows回收站功能的脚本
 
Generating Power with Yield
Generating Power with YieldGenerating Power with Yield
Generating Power with Yield
 
Redis & ZeroMQ: How to scale your application
Redis & ZeroMQ: How to scale your applicationRedis & ZeroMQ: How to scale your application
Redis & ZeroMQ: How to scale your application
 
Tugas Program C++
Tugas Program C++Tugas Program C++
Tugas Program C++
 
ZeroMQ: Messaging Made Simple
ZeroMQ: Messaging Made SimpleZeroMQ: Messaging Made Simple
ZeroMQ: Messaging Made Simple
 
What's new in PHP 5.5
What's new in PHP 5.5What's new in PHP 5.5
What's new in PHP 5.5
 
[2019] 아직도 돈 주고 DB 쓰나요? for Developer
[2019] 아직도 돈 주고 DB 쓰나요? for Developer[2019] 아직도 돈 주고 DB 쓰나요? for Developer
[2019] 아직도 돈 주고 DB 쓰나요? for Developer
 
Advanced modulinos
Advanced modulinosAdvanced modulinos
Advanced modulinos
 
Symfony messenger - PHPers Summit 2019
Symfony messenger - PHPers Summit 2019Symfony messenger - PHPers Summit 2019
Symfony messenger - PHPers Summit 2019
 

Viewers also liked

Scripting powerpoint
Scripting powerpointScripting powerpoint
Scripting powerpointmissSbennett
 
Loop
LoopLoop
Loop
kuldeep94
 
Toolbar
ToolbarToolbar
Toolbar
kuldeep94
 
Script
ScriptScript
Unitat4
Unitat4Unitat4
Unitat4Sergi
 
La reproducció i el desenvolupament dels organismes pluricel·lulars
La reproducció i el desenvolupament dels organismes pluricel·lularsLa reproducció i el desenvolupament dels organismes pluricel·lulars
La reproducció i el desenvolupament dels organismes pluricel·lulars
CC NN
 
Problemas de genética
Problemas de genéticaProblemas de genética
Problemas de genéticaCC NN
 
9.La reproducció i la relació de la cèl·lula eucariota
9.La reproducció i la relació de la cèl·lula eucariota9.La reproducció i la relació de la cèl·lula eucariota
9.La reproducció i la relació de la cèl·lula eucariota
CC NN
 
Reproducció sexual animals i plantes: Alicia, Irene, Raquel
Reproducció sexual animals i plantes: Alicia, Irene, RaquelReproducció sexual animals i plantes: Alicia, Irene, Raquel
Reproducció sexual animals i plantes: Alicia, Irene, Raquelromanica2neso
 
03loop conditional statements
03loop conditional statements03loop conditional statements
03loop conditional statements
Abdul Samad
 
Genètica i evolució II
Genètica i evolució IIGenètica i evolució II
Genètica i evolució II
CC NN
 
82. La reproducció asexual i sexual
82. La reproducció asexual i sexual82. La reproducció asexual i sexual
82. La reproducció asexual i sexual
Dani Ribo
 
Column writing
Column writingColumn writing
Dramatic Features of a Play.
Dramatic Features of a Play.Dramatic Features of a Play.
Dramatic Features of a Play.
Susan Lewington
 
Two dimensional geometric transformations
Two dimensional geometric transformationsTwo dimensional geometric transformations
Two dimensional geometric transformationsMohammad Sadiq
 
Editorial Writing 101
Editorial Writing 101Editorial Writing 101
Editorial Writing 101
Ken_Writer
 

Viewers also liked (20)

Scripting powerpoint
Scripting powerpointScripting powerpoint
Scripting powerpoint
 
Loop
LoopLoop
Loop
 
Toolbar
ToolbarToolbar
Toolbar
 
Script
ScriptScript
Script
 
Unitat4
Unitat4Unitat4
Unitat4
 
La reproducció i el desenvolupament dels organismes pluricel·lulars
La reproducció i el desenvolupament dels organismes pluricel·lularsLa reproducció i el desenvolupament dels organismes pluricel·lulars
La reproducció i el desenvolupament dels organismes pluricel·lulars
 
Problemas de genética
Problemas de genéticaProblemas de genética
Problemas de genética
 
9.La reproducció i la relació de la cèl·lula eucariota
9.La reproducció i la relació de la cèl·lula eucariota9.La reproducció i la relació de la cèl·lula eucariota
9.La reproducció i la relació de la cèl·lula eucariota
 
Reproducció sexual animals i plantes: Alicia, Irene, Raquel
Reproducció sexual animals i plantes: Alicia, Irene, RaquelReproducció sexual animals i plantes: Alicia, Irene, Raquel
Reproducció sexual animals i plantes: Alicia, Irene, Raquel
 
La reproducció i el desenvolupament
La reproducció i el desenvolupamentLa reproducció i el desenvolupament
La reproducció i el desenvolupament
 
03loop conditional statements
03loop conditional statements03loop conditional statements
03loop conditional statements
 
Genètica i evolució II
Genètica i evolució IIGenètica i evolució II
Genètica i evolució II
 
82. La reproducció asexual i sexual
82. La reproducció asexual i sexual82. La reproducció asexual i sexual
82. La reproducció asexual i sexual
 
Column writing
Column writingColumn writing
Column writing
 
Dramatic Features of a Play.
Dramatic Features of a Play.Dramatic Features of a Play.
Dramatic Features of a Play.
 
Two dimensional geometric transformations
Two dimensional geometric transformationsTwo dimensional geometric transformations
Two dimensional geometric transformations
 
Column writing
Column writingColumn writing
Column writing
 
Otto kernberg
Otto kernbergOtto kernberg
Otto kernberg
 
Editorial Writing 101
Editorial Writing 101Editorial Writing 101
Editorial Writing 101
 
Chl mj 164_ac
Chl mj 164_acChl mj 164_ac
Chl mj 164_ac
 

Similar to Scripting ppt

Unit vii wp ppt
Unit vii wp pptUnit vii wp ppt
Unit vii wp ppt
Bhavsingh Maloth
 
Syntax
SyntaxSyntax
Lecture 22
Lecture 22Lecture 22
Lecture 22rhshriva
 
Module 03 Programming on Linux
Module 03 Programming on LinuxModule 03 Programming on Linux
Module 03 Programming on Linux
Tushar B Kute
 
Shell programming
Shell programmingShell programming
Shell programming
Moayad Moawiah
 
2-introduction_to_shell_scripting
2-introduction_to_shell_scripting2-introduction_to_shell_scripting
2-introduction_to_shell_scriptingerbipulkumar
 
Ruby19 osdc-090418222718-phpapp02
Ruby19 osdc-090418222718-phpapp02Ruby19 osdc-090418222718-phpapp02
Ruby19 osdc-090418222718-phpapp02
Apoorvi Kapoor
 
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code style
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code styleRuby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code style
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code styleAnton Shemerey
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell ScriptingRaghu nath
 
Linux Shell Scripting
Linux Shell ScriptingLinux Shell Scripting
Linux Shell ScriptingRaghu nath
 
php programming.pptx
php programming.pptxphp programming.pptx
php programming.pptx
rani marri
 
Hypers and Gathers and Takes! Oh my!
Hypers and Gathers and Takes! Oh my!Hypers and Gathers and Takes! Oh my!
Hypers and Gathers and Takes! Oh my!
Workhorse Computing
 
UNIX - Class3 - Programming Constructs
UNIX - Class3 - Programming ConstructsUNIX - Class3 - Programming Constructs
UNIX - Class3 - Programming Constructs
Nihar Ranjan Paital
 

Similar to Scripting ppt (20)

Unit vii wp ppt
Unit vii wp pptUnit vii wp ppt
Unit vii wp ppt
 
Syntax
SyntaxSyntax
Syntax
 
Lecture 22
Lecture 22Lecture 22
Lecture 22
 
Shell Scripting
Shell ScriptingShell Scripting
Shell Scripting
 
Mips1
Mips1Mips1
Mips1
 
Lecture19-20
Lecture19-20Lecture19-20
Lecture19-20
 
Lecture19-20
Lecture19-20Lecture19-20
Lecture19-20
 
Module 03 Programming on Linux
Module 03 Programming on LinuxModule 03 Programming on Linux
Module 03 Programming on Linux
 
Shell programming
Shell programmingShell programming
Shell programming
 
tutorial7
tutorial7tutorial7
tutorial7
 
tutorial7
tutorial7tutorial7
tutorial7
 
2-introduction_to_shell_scripting
2-introduction_to_shell_scripting2-introduction_to_shell_scripting
2-introduction_to_shell_scripting
 
Ruby19 osdc-090418222718-phpapp02
Ruby19 osdc-090418222718-phpapp02Ruby19 osdc-090418222718-phpapp02
Ruby19 osdc-090418222718-phpapp02
 
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code style
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code styleRuby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code style
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code style
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell Scripting
 
Linux Shell Scripting
Linux Shell ScriptingLinux Shell Scripting
Linux Shell Scripting
 
Ruby
RubyRuby
Ruby
 
php programming.pptx
php programming.pptxphp programming.pptx
php programming.pptx
 
Hypers and Gathers and Takes! Oh my!
Hypers and Gathers and Takes! Oh my!Hypers and Gathers and Takes! Oh my!
Hypers and Gathers and Takes! Oh my!
 
UNIX - Class3 - Programming Constructs
UNIX - Class3 - Programming ConstructsUNIX - Class3 - Programming Constructs
UNIX - Class3 - Programming Constructs
 

Recently uploaded

Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
Marketing internship report file for MBA
Marketing internship report file for MBAMarketing internship report file for MBA
Marketing internship report file for MBA
gb193092
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
chanes7
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
Kartik Tiwari
 

Recently uploaded (20)

Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
Marketing internship report file for MBA
Marketing internship report file for MBAMarketing internship report file for MBA
Marketing internship report file for MBA
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
 

Scripting ppt

  • 1. Presentation on Looping Conditions and Command Line Arguments
  • 2. Conditional loop • conditional loop is a way for computer programs to repeat one or more various steps depending on conditions set either by the programmer initially or real-time by the actual program. • Basically a loop has a conditional statement or a command and body of that loop which has some list of commands or statements to be executed repeatedly.
  • 3. While Loop • The while loop is used to execute a set of commands repeatedly until some condition occurs. • It is usually used when the value of a variable has to be manipulated repeatedly.
  • 4. Basic syntax While command do list done It can also be written as, While command ; do list ; done
  • 5. Steps to execute a while loop 1. Execute command. 2. If the exit status of command is nonzero, exit from the while loop 3. If the exit status of command is zero, execute list. 4. When list finishes execution, return to step 1.
  • 6. For example, The output looks like, x=0 0 while [ $x –lt 10 ] 1 do 2 echo $x 3 x=`echo “$x + 1” | bc` 4 done 5 6 7 8 9
  • 7. Example(2) c=1 Output, while [ $c -le 5 ] Welcome 1 times do Welcome 2 times echo "Welcome $c Welcome 3 times times" Welcome 4 times (( c++ )) Welcome 5 times done
  • 8. Nested while loop • It is a loop in which a while loop will be a part of the body of another while loop. • There is no restrictions for the number of nested while loops. • But it will b better to avoid more than 5 nested loops.
  • 9. Syntax is, while command1 ; # this is loop1, the outer loop do list1 while command2 ; # this is loop2, the inner loop do list2 done list3 done
  • 10. Example, x=0 while [ "$x" -lt 10 ] ; # this is loop1 do y="$x" while [ "$y" -ge 0 ] ; # this is loop2 do echo "$y c" y=´echo "$y - 1" | bc´ done echo x=´echo "$x + 1" | bc´ done
  • 11. The output will be, 0 10 210 3210 43210 543210 6543210 76543210 876543210 9876543210
  • 12. For loop • The for loop is used to execute a set of commands repeatedly for each item in a list. • One of its most common uses is in performing the same set of commands for a large number of files.
  • 13. The common syntax is, for name in word1 word2 ... wordN do list done It can also be written as, for name in word1 word2 ... wordN ; do list ; done
  • 14. For a simple for loop, for i in 0 1 2 3 4 5 6 7 8 9 The output is, do 0 echo $i 1 done 2 3 4 5 6 7 8 9
  • 15. another example, for i in `cat 1.txt` Output is, do echo $i F done S T The contents in 1.txt, F S T
  • 16. Example(3) alphabet="a b c d e" Output, count=0 a for letter in $alphabet b do count=`expr $count + 1` c echo "Letter $count is d [$letter]" e done
  • 17. Command line arguments • The arguments used to pass to the shell scripts while interpreting are called command line arguments. • $0 indicates the name of the script. • $1 indicates the 1st argument of that script. • $2 indicates the 2nd argument. • $$ used to denote the process ID. • $# used to count the number of arguments. • $@ denotes all arguments.
  • 18. A simple example, var1=$1 var2=$2 var3=` expr $var1 + $var2 ` echo $var3 chmod +x file.sh ./file.sh 2 3 Output, 5
  • 19. Using argument status, var1=$1 chmod +x file1.sh var2=$2 ./file1.sh 2 3 var3=`expr $var1 + output, $var2` 5 if [$# -ne 2 ] then ./file1.sh 2 3 4 echo “no” Output, exit 1 no else echo $var3 fi