BCA UNIX LAB
BCA UNIX LAB
# Lab2 – Shell script to find whether the given year is leap year or not
clear
echo "enter a number"
read n
if [ `expr $n % 2` -eq 0 ]; then
echo " $n is even"
else
echo "$n is odd"
fi
#Lab 4 – Shell script to find the factorial of a given number
clear
echo "enter a number"
read n
if [ `expr $n % 2` -eq 0 ]; then
echo " $n is even"
else
echo "$n is odd"
fi
#Lab 4 – Shell script to find the factorial of a given number
clear
echo "enter a number"
read n
i=1
if [ $n -lt 0 ]; then
echo " you cannot find factorial for a negative number"
else
if [ $n -eq 0 ]; then
echo "factorial of zero is 1"
else
fact=1
while [ $i -le $n ]
do
fact=`expr $fact \* $i`
i=`expr $i + 1`
done
echo "the factorial of $n is $fact"
fi
fi
#Lab 7 – Shell script to print prime numbers between the give n limits m and n
n
clear
echo " enter m and n value"
read m n
while [ $m -le $n ]
do
i=2
flag=0
while [ $i -le `expr $m / 2` ]
do
if [ `expr $m % $i` -eq 0 ]
the
flag=1
break
else
i=`expr $i + 1`
fi
done
if [ $flag -eq 0 ]
then
echo $m
fi
m=`expr $m + 1`
done
# Lab 10 - Shell script to compression and decompression of files using gzip and gunzip
clear
echo "enter the file name"
read fname
echo "size of $file name before compression is"
wc -c $fname
gzip $fname
echo "size of file name after compression"
wc -c $fname.gz
#unzip the file
gunzip $fname.gz
echo "after decompression $fname"
wc -c $fname
echo $fname
echo "================================"
echo "uniq eliminates adjacent duplicate lines"
echo "======================================="
echo
echo unique lines of temp1
echo
echo "------------------------"
cat temp1 | sort | uniq;;
4) clear
echo "================================"
echo " rm -r deletes the directory along wih contents"
echo "============================================="
echo
echo "enter the subdirectory name"
read subdir
mkdir $subdir
cd $subdir
touch file1 file2
echo current directory is `pwd`
cd ..
if rm -r $subdir
then
echo $subdir removed succesffully
fi;;
*) echo "invalid choice"
esac
echo "do you like to continue ?"
read opt
done
echo
tail -$n temp;;
#Lab 12 - To check
whether the file exists or
not if it exists give
details of its attributes
like
access permission, size
and etc
#Lab 12 - To check whether the file exists or not if it exists give details of its attributes like
access permission, size and etc.
clear
echo "enter the file name"
read fname
if [ -e $fname ]
then
echo "$fname exists and its attributes are "
ls -l $fname
else
echo "$fname does not exist"
fi
esac
echo "do you want to continue y/n "
read option
done