Linux Workshop

Ayush BhosaleAyush Bhosale
3 min read

Hey guys....!

I am back here with my another blog. Today I attend another session of Linux workshop. This blog presents the topic covered on day 8 of the Linux workshop conducted by Mr.Pranav Jambare sir.

so, let's start with the contents of Day 8.

Contents

  • While Loop

  • Until Loop

  • For Loop

  • Command Line Arguments

While Loop

  • If the condition remains satisfied the loop runs.

  • The while loop repeatedly executes the commands inside the loop as long as the condition remains true.

  • The while loop repeatedly executes the commands inside the loop as long as the condition remains true.

Syntax :-

    #Syntax 
while <command>
do
     statement executed if the command is true
done

Example :-

#!/bin/bash
a=0
while [ ${A} -lt 20 ]
do
    echo "number is ${A}"
    A = `expr ${A} + 1`
done

Until Loop

  • If the condition remains unsatisfied the loops run.

  • In shell scripting, the until loop is similar to the while loop, but it executes a block of code repeatedly until a certain condition becomes true

Syntax :-

    #Syntax 
until <condition>
do
    statement executed if the command is true
done

Example :-

#!/bin/bash
a=20
while [ ${A} -lt 0 ]
do
    echo "number is ${A}"
    A = `expr ${A} - 1`
done

For Loop

  • It is a control flow statement for specifying iteration.

  • The commands inside the loop are executed for each item in the list.

    Syntax :-

#Syntax 
for var in word1 word2..wordn              --(var=variable)
do
statements executed till element end
done

Example :-

#example
#!/bin/bash
for var in $(cat /root/names)
do
echo "${var}"
done

Command Line Arguments

  • $1 $2 $3 :- Arguments passed

  • $0 :- Name of the shell program

  • $@ :- One by one argument passed

  • $# :- Total number of arguments

  • $* :- All arguments together

  • $$ :- PID(Process ID) of current shell. (Actually the program PID can be achieve)

  • $? :- Status of last command

  • $! :- PID of last command.

#example
#!/bin/bash
for names in $1 $2 $3;
do
    echo "My name is ${name}"
    echo "My program name is $0"
    echo "$#"
    echo "$*"
    echo "$$ last prg pid"
    sleep 200
    echo "$? last comnd run"
    echo "$! last comnd pid"
done

#output
My name is Ayush
My file name is dynamic.sh
3
ayush aryan unmesh
5103 last prg pid
0 last comnd run
2637 last comnd pid

These important topics are covered on the day 8 of the Linux Workshop. I hope you enjoy it.

Thank you for reading the blog......!!!!

10
Subscribe to my newsletter

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

Written by

Ayush Bhosale
Ayush Bhosale

Student at Dr. Babasaheb Ambedkar University Lonere, in computer science