0% found this document useful (0 votes)
46 views4 pages

De La Salle University: College of Engineering, Architecture and Technology

This document contains two programs written in bash shell scripting to perform basic file and directory operations: 1) A program that asks the user to input a number and calculates the average of even and odd numbers from 1 to the input number. 2) A basic command program that displays options for users to create/delete directories, rename/copy files, list directories, and execute files by running the corresponding bash commands. It prompts the user to run the program again after completing each task.
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)
46 views4 pages

De La Salle University: College of Engineering, Architecture and Technology

This document contains two programs written in bash shell scripting to perform basic file and directory operations: 1) A program that asks the user to input a number and calculates the average of even and odd numbers from 1 to the input number. 2) A basic command program that displays options for users to create/delete directories, rename/copy files, list directories, and execute files by running the corresponding bash commands. It prompts the user to run the program again after completing each task.
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/ 4

COLLEGE OF ENGINEERING, ARCHITECTURE AND TECHNOLOGY

DE LA SALLE UNIVERSITY
Cavite Philippines

OPERATING SYSTEM

(CPET 529L)

Deadlocks
Laboratory Exercise #

GRADE

Group No. : ____ Signature

Leader :

Members :
TAFALLA,Rafael Gabriel A.

Date Performed : March 30 2019


Date Submitted : April 6 2019

Prof. Michael C. Olivo


Lab Instructor
 Create a program that will ask the user to enter a number and display the
average of even and odd numbers

CODE:
echo "Enter a number :"
read n
a=1
b=1
while [ $a -le $n ]
do
eo=$(( $a % 2))
if [ $eo -eq 0 ]
then
echo "The evens numbers are :"$a
sum=$(($sum+$a))
num=$(($a/$a))
tot=$(($tot+$num))
fi
a=$((a+1))
done

while [ $b -le $n ]
do
eoe=$(( $b % 2))
if [ $eoe -ne 0 ]
then
echo "The odd numbers are :"$b
sum1=$(($sum1+$b))
num1=$(($b/$b))
tot1=$(($tot1+$num1))
fi
b=$((b+1))
done
aves=$(echo "scale=2; $sum/$tot"|bc)
aveo=$(echo "scale=2; $sum1/$tot1"|bc)
echo "The average of odd numbers are " $aveo
echo "The average of even numbers are " $aves

echo "Try Again?[Y/y]"


read b
T="Y"
t="y"
if [[ $b == "y" ]]||[[ $b == "Y" ]]
then
bash oe.sh
fi

 Basic Command Program


echo "[A/a]Create Directory"
echo "[B/b]Rename File"
echo "[C/c]Delete File and Directory"
echo "[D/d]Copy Files"
echo "[E/e]List Directory"
echo "[F/f]Execute File"
echo "[G/g]Exit"
echo "Choose an Option"
read a

if [[ $a == "A" ]]||[[ $a == "a" ]]


then
echo "Enter a name of the directory"
read d
mkdir $d
echo "Directory $d has been created in the desktop"
fi

if [[ $a == "B" ]]||[[ $a == "b" ]]


then
echo "Enter the filename to be renamed from desktop"
read n
echo "Enter the new name"
read new
mv $n $new
echo "$n ha been renamed to $new"
fi

if [[ $a == "C" ]]||[[ $a == "c" ]]


then
echo "Enter the name of directory to be removed"
read del
rm -r $del
echo "Directory $del has been deleted from the desktop"
fi

if [[ $a == "D" ]]||[[ $a == "d" ]]


then
echo "Enter the name of the file to Copied from desktop to desktop"
read c
echo "Enter the new name of the file that will be copied"
read copy
cp $c $copy
echo "Filename $copy has been copied in desktop"
fi

if [[ $a == "E" ]]||[[ $a == "e" ]]


then
ls -l
fi

if [[ $a == "F" ]]||[[ $a == "f" ]]


then
echo "Enter the filename to be Executed from desktop"
read ex
bash $ex
fi

if [[ $a == "G" ]]||[[ $a == "g" ]]


then
exit
fi

echo "Try Again?[Y/y]"


read b
if [[ $b == "y" ]]||[[ $b == "Y" ]]
then
bash ex4.sh
fi

You might also like