#!/bin/sh
[sourcecode language='sh'] echo Enter a Number read num1 echo Enter Number read num2 if test $num1 -ge $num2 then echo $num1 is greater than $num2 else echo $num2 is greater than $num1 fi 2) Shell Program to Check a number is even or odd
[sourcecode language='sh'] echo Enter a Number to Find Even or odd read num b=`expr $num % 2` if [ $b -eq 0 ] then echo Even number else echo Odd Number fi 3) Shell Program to check whether a year is leap or Not
[sourcecode language='sh'] echo Enter the year to check for Leap read year leap=`expr $year % 4` check1=`expr $year % 100` if [ $check1 -eq 0 ] then check2=`expr $year % 400 | bc` if [ $check2 -eq 0 ] then echo Leap else echo Not Leap fi break; fi if [ $leap -eq 0 -a $check1 -ne 0 ] then echo Leap fi 4) Shell Program to Find a File exists in the present working directory echo Enter a File Name read filename if [ -s $filename ] then if [ -f $filename ] then echo File Exists… else echo Directory Exists… fi ls $filename -n else echo Not found fi [/sourcecode]
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 ] then echo "Usage - $0 x y" echo " Where x and y are two nos for which I will print sum" exit 1 fi 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
#