Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Write a script to help users calculate compressed file size. Prompt the user

ID: 3561839 • Letter: 1

Question

1. Write a script to help users calculate compressed file size. Prompt the user to enter the original size of a file (in bytes) from the keyboard. Then use the following rules for calculating the compressed file size. Display the result on the screen.

* If the size is less than 5000 bytes, the compression ratio is 90%;

* If the size is between 5000 and 50000 bytes, the compression ratio is 70%;

* If the size is more than 50000 bytes, the compression ratio is 40%.

2. Develop a small console program driven by a text menu (see the sample screenshot below):

* It displays a simple menu with 4 items indicated by number 1-4.

* Users will enter number 1 to 4 to run some commands.

* Item #1 to #3 will run some shell commands (it

Explanation / Answer

#! /bin/bash

echo "Please enter file size"
read fsize

if [ $fsize -lt "5000" ]
then
echo "the compression ratio is 90%"
elif [ $fsize -ge "5000" ] && [ $fsize -lt "50000" ]
then
echo "the compression ratio is 70%"
else
echo "the compression ratio is 40%"
fi
exit 0


#! /bin/bash

echo "Menu"
echo "1 print current directory"
echo "2 list files in current directory"
echo "3 print date"
echo "4 exit"
echo "Please enter number 1 to 4"
read u

while [ $u -ne 4 ]
do
if [ $u -eq 1 ]
then
pwd
elif [ $u -eq 2 ]
then
ls
elif [ $u -eq 3 ]
then
date
fi
echo "Please enter number 1 to 4"
read u
done

exit 0