echo Enter a Number
echo Enter Number
if test $num1 -ge $num2
then echo $num1 is greater than $num2
echo $num2 is greater than $num1
2) Shell Program to Check a number is even or odd
echo Enter a Number to Find Even or odd
b=`expr $num % 2`
if [ $b -eq 0 ]
echo Even number
echo Odd Number
3) Shell Program to check whether a year is leap or Not
echo Enter the year to check for Leap
leap=`expr $year % 4`
check1=`expr $year % 100`
if [ $check1 -eq 0 ]
check2=`expr $year % 400 | bc`
if [ $check2 -eq 0 ]
echo Not Leap
if [ $leap -eq 0 -a $check1 -ne 0 ]
4) Shell Program to Find a File exists in the present working directory echo Enter a File Name
if [ -s $filename ]
if [ -f $filename ]
echo File Exists…
echo Directory Exists…
ls $filename -n
echo Not found
5) Shell Program To copy a file into another file
echo Enter Source File Name Destination File name
read srcfile destfile
cp $srcfile $destfile
echo Copy Complete…
echo $destfile “Is a Copy of ” $srcfile
6) How to write shell script that will add two nos, which are supplied as command line argument, and if this two nos are not given show error and its usage
if [ $# -ne 2 ]
echo "Usage - $0 x y"
echo " Where x and y are two nos for which I will print sum" exit 1
echo "Sum of $1 and $2 is `expr $1 + $2`"
7) Write Script to find out biggest number from given three nos. Nos are supplies as command line argument. Print error if sufficient arguments are not supplied. # Algo:
# 1) START: Take three nos as n1,n2,n3.
# 2) Is n1 is greater than n2 and n3, if yes
# print n1 is bigest no goto step 5, otherwise goto next step # 3) Is n2 is greater than n1 and n3, if yes
# print n2 is bigest no goto step 5, otherwise goto next step # 4) Is n3 is greater than n1 and n2, if yes
# print n3 is bigest no goto step 5, otherwise goto next step # 5) END
if [ $# -ne 3 ]
echo "$0: number1 number2 number3 are not given" >&2
if [ $n1 -gt $n2 ] && [ $n1 -gt $n3 ]
echo "$n1 is Bigest number"
elif [ $n2 -gt $n1 ] && [ $n2 -gt $n3 ]
echo "$n2 is Bigest number"
elif [ $n3 -gt $n1 ] && [ $n3 -gt $n2 ]
echo "$n3 is Bigest number"
elif [ $1 -eq $2 ] && [ $1 -eq $3 ] && [ $2 -eq $3 ]
echo "All the three numbers are equal"
echo "I can not figure out which number is biger" fi
8) Write script to print nos as 5,4,3,2,1 using while loop.
# 1) START: set value of i to 5 (since we want to start from 5, if you # want to start from other value put that value)
# 2) Start While Loop
# 3) Chechk, Is value of i is zero, If yes goto step 5 else # continue with next step
# 4) print i, decement i by 1 (i.e. i=i-1 to goto zero) and # goto step 3
# 5) END
while test $i != 0
i=`expr $i - 1`
9)Write Script, using case statement to perform basic math operation as follows
if test $# = 3
case $2 in
+) let z=$1+$3;;
-) let z=$1-$3;;
/) let z=$1/$3;;
x|X) let z=$1*$3;;
*) echo Warning - $2 invalied operator, only +,-,x,/ operator allowed
echo Answer is $z
echo "Usage - $0 value1 operator value2"
echo " Where, value1 and value2 are numeric values"
echo " operator can be +,-,/,x (For...