BCE-O535 Linux and Shell Programming

0 of 30 lessons complete (0%)

Module 6 Introduction to Shell

Program 3: Using Parameters in Shell

You don’t have access to this lesson

Please complete the prerequisites to view this lesson content.

Step 1: Create a File

For Patterns, a file is needed with text, so create a file in the same folder where you are creating your script.

Filename: file1

India extended their winning streak with a commanding eight-wicket victory over Afghanistan in the World Cup on Wednesday.

In pursuit of a target of 273 runs, Rohit Sharma unleashed a barrage of sixes, smashing a blistering 131 off just 84 balls. This remarkable innings not only secured India's victory but also etched Sharma's name in the history books as he became the player with the most centuries in World Cup history. Alongside Sharma, Ishan Kishan (47), Virat Kohli (55 not out), and Shreyas Iyer (25 not out) made valuable contributions to ensure a comfortable win for the hosts, reaching the target in just 35 overs.

The opening partnership between Sharma and Kishan was a pivotal moment in the match, as their 156-run stand laid a solid foundation for India's successful chase.

Step 2: Write your script

Filename: p2.sh

$ cat p3.sh
echo "Program: $0"
echo "The number of arguments specified is: $#"
echo "The arguments are $*"
grep "$1" $2
echo "\nJob Over"

Step 3: Run your Script

//Give permission to execute file
$chmod 744 p2.sh

//verify permission    
$ls -l p2.sh       

//Run Your Script
$./p2.sh India file

Step 4: Output

Program: p2.sh
The number of arguments specified is: 2
The arguments are India file

Hurray you have done it…