[go: up one dir, main page]

0% found this document useful (0 votes)
42 views20 pages

OS Lab

This document contains the details of 15 experiments performed on operating system concepts like commands, loops, conditions, arguments in a college level lab course. The experiments cover basic and important OS concepts - using echo and comments, while, for and case loops, if/else conditions, getting user input, comparing arguments and combining strings. The output for each experiment is included showing the concept being demonstrated.

Uploaded by

Priyanshu Raj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views20 pages

OS Lab

This document contains the details of 15 experiments performed on operating system concepts like commands, loops, conditions, arguments in a college level lab course. The experiments cover basic and important OS concepts - using echo and comments, while, for and case loops, if/else conditions, getting user input, comparing arguments and combining strings. The output for each experiment is included showing the concept being demonstrated.

Uploaded by

Priyanshu Raj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 20

MAULANA ABUL KALAM

AZAD UNIVERSITY OF
TECHNOLOGY

NAME-RISHAV KUMAR
ROLL-30000218016
REGD NO-183000110056
DEPARTMENT-INFORMATION TECHNOLOGY
SEMESTER-5TH
SUBJECT-OPERATING SYSTEM LAB
EXPERIMENT – 01
Name of experiment : Hello World
Objective: To get output of the command ‘Hello World’.

Program:
echo "Hello World!"

Output: Hello World!

EXPERIMENT – 02
Name of experiment : Echo Command
Objective: Use of echo command

Program:
We can use echo command with various options.
1. When you use ‘echo’ command without any option then
a newline is added by default.
2. ‘-n’ option is used to print any text without new line.
3. ‘-e’ option is used to remove backslash characters from
the output.
echo "Printing text with newline"
echo -n "Printing text without newline"
echo -e "\nRemoving \t backslash \t characters\n"

Output:
Printing text with newline
Printing text without newline
Removing backslash characters
EXPERIMENT – 03
Name of experiment : Comments
Objective: Use of comment
Program:
‘#’ symbol is used to add single line comment in bash script.
# Add two numeric value
((sum=25+35))
#Print the result
echo $sum

Output: 60
EXPERIMENT – 04
Name of experiment : Multi-line comment
Objective: Use of Multi-line comment
Program:
: 'The following script calculates the square value of the
number, 5.'
((area=5*5))
echo $area

Output:
25
EXPERIMENT – 05
Name of experiment : While Loop
Objective: Using While Loop
Program:
valid=true
count=1
while [ $valid ]
do
echo $count
if [ $count -eq 5 ];
then
break
fi
((count++))
done
Output:
1
2
3
4
5

EXPERIMENT – 06
Name of experiment : For Loop
Objective: Using For Loop
Program:
for color in Blue Green Pink White Red
do
echo "Color = $color"
done

Output:
Color = Blue Color = Green Color = Pink Color = White
Color = Red

EXPERIMENT – 07
Name of experiment : Get User Input
Objective: Get User Input
Program:
echo “Enter your college name”
read name
echo “This is $name”

Output: This is Your college name:- Makaut

EXPERIMENT – 08
Name of experiment : If statement
Objective: Using if statement
Program:
n=8
if [ $n -lt 10 ];
then
echo "It is a one digit number"
else
echo "It is a two digit number"
fi
Output: It is a one digit number

EXPERIMENT – 09
Name of experiment : And Condition if statement
Objective: Using if statement with AND logic
Program:
echo "Enter username"
read username
echo "Enter password"
read password
if [[ ( $username == "admin" && $password == "pass123" ) ]]; then
echo "valid user"
else
echo "invalid user"
fi

Input:
Enter username
admin
Enter password
pass
Output:-
Invalid user

EXPERIMENT – 10
Name of experiment : Or Condition if statement
Objective: Using if statement with OR logic
Program:
echo "Enter any number"
read n
if [[ ( $n -eq 15 || $n -eq 45 ) ]]
then
echo "You won the game"
else
echo "You lost the game"
fi

Output :
Enter any number
45
You won the game
EXPERIMENT – 11
Name of experiment : Else if and else condition
Objective: Using else if statement
Program:
echo "Enter your lucky number"
read n
if [ $n -eq 101 ];
then
echo "You got 1st prize"
elif [ $n -eq 510 ];
then
echo "You got 2nd prize"
elif [ $n -eq 999 ];
then
echo "You got 3rd prize"
else
echo "Sorry, try for the next time"
fi
Output:
Enter your lucky number
88
Sorry, try for the next time

EXPERIMENT – 12
Name of experiment : Case Condition
Objective: Using Case Statement
Program:
echo "Enter your lucky number"
read n
case $n in
101)
echo echo "You got 1st prize" ;;
510)
echo "You got 2nd prize" ;;
999)
echo "You got 3rd prize" ;;
*)
echo "Sorry, try for the next time" ;;
esac

Output:
Enter your lucky number
101
You got 1st prize

EXPERIMENT – 13
Name of experiment : Get Arguments from Command Line
Objective: Get Arguments from Command Line
Program:
echo "Total arguments : $#"
echo "1st Argument = $1"
echo "2nd argument = $2"

Output :
Total arguments : 2
1st Argument = Linux
2nd argument = Windows
EXPERIMENT – 14
Name of experiment : Get arguments from command line
with names
Objective: Get arguments from command line with names
Program:
for arg in "$@"
do
index=$(echo $arg | cut -f1 -d=)
val=$(echo $arg | cut -f2 -d=)
case $index in
X) x=$val;;
Y) y=$val;;
*)
esac
done
((result=x+y))
echo "X+Y=$result"
Output:
X + Y = 100

EXPERIMENT – 15
Name of experiment : Combine two strings in a variable
Objective: Combine String variables
Program:
string1="West"
string2="Bengal"
echo "$string1$string2"
string3=$string1+$string2
string3+=" is 4th populated state"
echo $string3

Output:
West Bengal
West Bengal is 4th populated state
Thank you

You might also like