Alphabet related program

EX.NO:2.mPRINT EXIST FILE WHICH STARTING WITH SAME

ALPHABET

 

Aim:

Write a shell program to print existing file which starting with same alphabet.

 

Algorithm:

 

Step1: Start

Step2:In a BASH, “for” loop all, the statements between do and done are performed once every item in the list. Each time the loop iterates, the next value in the list is inserted into the variable specified after the word for. In the below loop, the variable is called k.

Step3: The echo statement displays information to the screen.All t file name in the list display one by one to the screen.

Step4:Stop

 

Program code:

 

for k in t*

do

            echo "File name is $k"

done

 

Sample O/P:

 

File name is t*

File name is tt.sh

File name is t1.sh

 

Result:

Thus the shell program is executed and output is verified successful

 

VIVA-VOCE QUESTIONS:

 

1. What is the syntax of “for” loop?

2. What is the syntax of do ,done and in?

3. What is the purpose of “echo ” command?

 

 

 

 

 

 

 

 

 

EX.NO:3.aPRINT ALL ARGUMENTS

 

Aim:

Write a shell program to print arguments which were entered on the command line.

 

 

Algorithm:

 

Step1: Start

Step2:In a BASH, “for” loop all, the statements between do and done are performed once every item in the list. Each time the loop iterates, the next value in the list is inserted into the variable specified after the word for. In the below loop, the variable is called arg.

Step3: $* Stores all the arguments that were entered on the command line($1 $2..)

Step4:The echo statement display the all arguments to the screen.

Step4:Stop

 

Program code:

for arg in $*

do

            echo $arg

done

 

Sample I/P:

hello world earth

Sample O/P:

hello world earth

Result:

Thus the shell program is executed and output is verified successfully.

 

 

VIVA-VOCE QUESTIONS:

1. What is syntax of for loop in Shell?

2. What does $* mean?

 

 

 

 

 

 

 

 

 

EX.NoO:3.bPRINT CONTENTS OF ALL EXIST FILE WHICH

STARTING FILE NAME WITH SAME ALPHABET

 

Aim:

Write a shell program to print existing file which starting with same alphabet.

 

Algorithm:

 

Step1: Start

Step2:In a BASH, “for” loop all, the statements between do and done are performed once every item in the list. Each time the loop iterates, the next value in the list is inserted into the variable specified after the word for. In the below loop, the variable is called f.

Step3: contents of the all t file name in the list display one by one to the output screen.

Step4:Stop

Program code:

Vi f1.sh

 

for f in t*

do

            cat $f

done

 

Sample O/P:

Sh f1.sh

 

for k in t*

do

            echo "File name is $k"

done

 

for arg in $*

do

            echo $arg

done

Result:

Thus the shell program is executed and output is verified successfully.

 

 

VIVA-VOCE QUESTIONS:

 

1. the purpose of “cat” command?

2. What does t* mean?

 

 

EX.NO:3.cPRINT DIVISION AND MULTIPLICATION

 

 

Aim:

To Write a shell Program to define x=20 y=5 and print division of x and y and multiplication of x and y.

 

Algorithm:

 

Step1: Define x=20 and y=5.

 Step2:Print the  arithmetic operations which we are going to perform

Step 3 : Check the corresponding operations.

Step 5 : Print the result and stop the execution.

.

 

Programcode:

x =20

y =5

echo"division="

echo`expr$x / $y`

echo"multiplication ="

echo`expr$x \* $y`

 

Sample I/P:

 

 

Sample O/P:

 

division= 4

multiplication = 100          

Result:

Thus the shell program to print division of x and y and multiplication of x and y is executed and output is verified successfully.

 

VIVA-VOCE QUESTIONS:

 

1. What is the use of “expr” in Linux?

2. What are the symbols for multiplication with expr in shell script?

3. What are the symbols for division with expr in shell script

 

 

 


 

Comments

Popular posts from this blog

what is Machenical Engineering

PHOTO ( CHINESE LADKA)

Arithmatic operations, factorial of a number, while loop, prime number, etc