The beginning of a Linux Story

Rihaab WadekarRihaab Wadekar
2 min read

Welcome to the day-8 blog of the Linux workshop Guided by Mr Pranav Jambare .

The following Topics were covered on Day 8 of the workshop.


Loops In Shell Script

  • a Loop is used to execute a group of instructions or a block of code multiple times, without writing it repeatedly.

  • The block of code is executed based on a certain condition.

Types Of Loops:

While loop

A while loop allows code to be executed repeatedly based on a given Boolean condition.

#Sytax
while command
do
   Statements to be executed 
done

For loop

The for loop operates on lists of items. It repeats a set of commands for every item in a list.

#Syntax
for var in word1 word2 ... wordN
do
   Statements to be executed 
done

Until loop

The Until loop is used to iterate over a block of commands until the required condition is false.

#Syntax
until command
do
   Statements to be executed
done

Select loop

The select loop provides an easy way to create a numbered menu from which users can select options.

#Syntax
select var in word1 word2 ... wordN
do
   Statements to be executed.
done

Command Line Arguments

  • Command Line Arguments are inputs or parameters provided to a command or script when it is executed in the terminal.

  • $1 $2 $3 ==> The first command-line argument is represented by $1, the second one by $2, and so on.

  • $0 ==> Represents the name of the script itself.

  • $@ ==> Passing arguments one-by-one

  • $# ==> Total number of command line arguments provided

  • $* ==> Represents all the command-line arguments as a single string

  • $$==> Represents the process ID (PID) of the currently running shell or script

  • $? ==> Holds the status of the last executed command

  • $!==> Hold the process ID (PID) of the last executed command

0
Subscribe to my newsletter

Read articles from Rihaab Wadekar directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Rihaab Wadekar
Rihaab Wadekar