0% found this document useful (0 votes)
54 views6 pages

OS Lab Report # 04 & 05 by Kamran Jalil 19pwcse1751

This document contains a lab report submitted by Kamran Jalil for their Operating Systems Lab course. It details 5 programming assignments completed in Shell programming. The assignments include writing scripts to: 1) Copy files and perform basic math operations using parameters, 2) Search for filenames containing a keyword, 3) Check if a command line argument is a file, directory, or link, 4) Count subdirectories in a given directory, and 5) Create a menu-driven program to search for files or display logged in users. Code snippets are provided as examples for each assignment.

Uploaded by

urooj qaiser
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)
54 views6 pages

OS Lab Report # 04 & 05 by Kamran Jalil 19pwcse1751

This document contains a lab report submitted by Kamran Jalil for their Operating Systems Lab course. It details 5 programming assignments completed in Shell programming. The assignments include writing scripts to: 1) Copy files and perform basic math operations using parameters, 2) Search for filenames containing a keyword, 3) Check if a command line argument is a file, directory, or link, 4) Count subdirectories in a given directory, and 5) Create a menu-driven program to search for files or display logged in users. Code snippets are provided as examples for each assignment.

Uploaded by

urooj qaiser
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/ 6

“SHELL PROGRAMMING (Part I & II)”

Lab Report # 04 & 05

Spring 2021

CSE 204L: Operating Systems Lab


Submitted by: KAMRAN JALIL
Registration # 19PWCSE1751
Class Section: B

Submitted to:
Engr. Mian Ibad Ali Shah

03 May, 2021.
Assignment Problems on UNIX SHELL programming

1. Run all the programs given in the Lab Notes, and observe the output for each
program.
Done

Some Examples are as follows


Example:
echo What is your name\?
read name
echo Hello $name Assalam-o-Alaikum.

Example:
echo Please Enter source file name:
read source
echo Enter the target file name:
read target
cp $source $target
echo file $source is copied into the $target

Example:
echo the parameters passed are: $1, $2, $3, $4, $5
echo the name of the script is: $0
echo the number of parameters passed are: $#
sum=`expr $1 + $2 + $3 + $4 + $5`
echo the sum is: $sum
Example:
sum=0
while [ $# -gt 0 ]
do
sum=`expr $sum + $1`
shift
done
echo sum is $sum

Example:
echo Enter a:
read a
echo Enter b:
read b

if [ $a == $b ]
then
echo a is equal to b
elif [ $a -gt $b ]
then
echo a is greater than b
elif [ $a -lt $b ]
then
echo a is less than b
else
echo None of the condition met
fi
2. Write a shell script that takes a keyword as a command line argument and lists the
filenames containing the keyword.
Code:
gedit labtasks

echo Enter a Keyword


read key
ls *$key*

3. Write a shell script that takes a command line argument and reports whether it is a
directory, or a file or a link.
Code:
echo enter a name of the File or directory
read name
test -f $name
$?=$a
test -d $name
$?=$b
if [$a == 0 -a $b == 1]
then
echo $name is a file
elif [$a == 1 -a $b == 0]
then
echo $name is a Directory
else
echo It is a link
fi
4. Write a script to find the number of sub directories in a given directory.
Code:
echo enter the name of directory
read ndr
cd $ndr
ls > drl
sort drl
echo number of subdirectories are: ` wc -l drl`
5. Write a menu driven program that has the following options.
a. Search a given file is in the directory or not.
b. Display the names of the users logged in.
Code:
echo Enter One of the following
echo 1. Search a given file in Current Directory
echo 2. Display the names of users logged in
read text

case $text in
1) echo Enter a File Name
read name
find . -name $name -print;;

2) who;;

*) echo Invalid Entry;;


Esac

*********************************

You might also like