0% found this document useful (0 votes)
5 views

OSY OUTPUT 10 TO 13

The document provides a series of practical shell scripts demonstrating the use of control statements such as 'if', 'for', and permission checks. It includes scripts for grading based on percentage, checking file existence, and verifying file permissions. Each script is accompanied by example outputs to illustrate functionality.

Uploaded by

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

OSY OUTPUT 10 TO 13

The document provides a series of practical shell scripts demonstrating the use of control statements such as 'if', 'for', and permission checks. It includes scripts for grading based on percentage, checking file existence, and verifying file permissions. Each script is accompanied by example outputs to illustrate functionality.

Uploaded by

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

PRACTICAL NO .

10
Q. Execute Shell Script by using if statement.

echo "Enter percentage here :"


read grade
if [ $grade -ge 90 ] && [ $grade -le 100 ]
then
echo "Grade A"
fi
if [ $grade -ge 70 ] && [ $grade -lt 90 ]
then
echo "Grade B"
fi
if [ $grade -ge 50 ] && [ $grade -lt 70 ]
then
echo "Grade C"
fi
if [ $grade -ge 35 ] && [ $grade -lt 50 ]
then
echo "Grade D"
fi
if [ $grade -lt 35 ]
then
echo "FAIL"
fi

OUTPUT

ENTER PERCENTAGE HERE


90
GRADE A
terminal@terminal-
Double Decision:-

echo "Enter percentage of Student : "


read grade
if [ $grade -gt 40 ]
then
echo "Pass"
else
echo "Fail"
fi

OUTPUT

terminal@terminal-temple ~ $: Desktop$ ./double.sh


Enter percentage of student :
40
Fall
terminal@terminal-temple ~ $:Desktop$ ./double.sh
Enter percentage of student :
60
Pass
terminal@terminal-temple ~ $ Desktop$
PRACTICAL NO .11
Q. Write and execute Shell Script by using following Control statements features
“for” statement, exit, break, continue.

read -p 'Enter no = ' no


echo "Table of $no"
for (( i=1; i<=10; i++ ))
do
echo " "$(( no * i ))
done
OUTPUT
terminal@terminal-temple ~ $ chmod ugo+x for .sh
terminal@terminal-temple ~$
Enter no = 10
Table of 10
10
20
30
40
50
60
70
80
90
100
no="1 2 3 4 5 6 7"
for n in $no
do
q=$(( $n % 2 ))
if test $q -eq 0
then
echo "even"
continue
fi
echo "odd"
done

OUTPUT
terminal@terminal ~$ Desktop/Shell$ chmod ugo+x evenodd.sh
terminal@terminal ~$ Desktop/Shell$ ./evenodd.sh
odd
even
odd
even
odd
even
odd
terminal@terminal ~$ Desktop/Shell$
PRACTICAL NO .12
Q.Write Shell Script to find out whether – Given file exists?

echo "Enter file or directory name"

read file
if [ -f "$file" ]
then
echo "$file It is a file"
else
if [ -d "$file" ]
then
echo "$file It is a directory"
fi
OUTPUT
terminal@terminal ~$ Desktop/Shell$ mkdir ul
terminal@terminal ~$ -/Desktop/Shell$ ls case.sh double.sh
execpwd.sh f
dir.sh evenodd.sh exec.sh file.sh greatest.sh login.sh fibo.sh for.sh
pattern.sh permission.sh single.sh table.sh week.sh lessthan.sh
multiple.sh patt.sh san.sh sun.sh 01
terminal@terminal ~$ /Desktop/Shell$ ./dtr.sh
Enter file or directory name:
U1 ul is a directory
terminal@terminal ~$ Desktop/Shell$ ./dtr.sh
Enter file or directory name:
multiple.sh
multiple.sh is a file
PRACTICAL NO .13
Q. Write a shell script to find out whether - File has read, write and execute
permissions.

echo ―Enter the File : ‖


read line
if [ -r $line ]
then
echo ―$line has all the read permissions‖
fi
if [ -x $line ]
then
echo ―$line has all the execute permissions‖
fi
if [ -w $line ]
then
echo ―$line has all the write permissions‖
fi
OUTPUT
terminal@terminal ~$:Desktop/Shell$ chmod ugo+x permission.sh
utkarsha@utkarsha-VirtualBox:~/Desktop/Shell$ ./permission.sh
Enter the File :
permission.sh
permission.sh has all the read
permissions permission.sh has all the execute permissions
permission.sh has all the write permissions
Q.Write a shell script which displays a list of all the files in the current
directory to which user has read, write and execute permission.
pwd
ls > f
exec < f
while read line
do
if [ -f $line ]
then
if [ -r $line –a –w $line –a –x $line ]
then
echo ―$line has all the permissions‖
fi
fi
done
OUTPUT
terminal@terminal ~$:Desktop/Shell$ chmod ugo+x exec.sh
terminal@terminal ~$:Desktop/Shell$ ./exec.sh
/home/aayush/Desktop/Shell double.sh has all the permissions
execpwd.sh has all the permissions
exec.sh has all the permissions
greatest.sh has all the permissions
login.sh has all the permisstons
multiple.sh has all the permissions
permission.sh has all the permissions
sam.sh has all the permissions
single.sh has all the permissions

You might also like