Sie sind auf Seite 1von 7

#Shell program to find biggest among three numbers: echo -n Enter three numbers read a b c if [ $a gt $b a $a gt $c ] then echo -n $a is the

biggest. elif [ $b gt $c ] then echo -n $b is the biggest. else echo -n $c is the biggest. fi SAMPLE INPUT/OUTPUT: $sh big.sh Enter three numbers: 2 6 5 6 is the biggest.

#Shell program to find odd or even numbers: echo n Enter a number: read num r=`expr $num % 2` if [ $r eq 0] then echo -n $num is an even number. else echo -n $num is an odd number. fi SAMPLE INPUT/OUTPUT: $sh odd.sh Enter a number: 54 54 is an even number.

#Shell program to check the given year leap or not: echo n Enter a year read year yr= `expr $year % 4` if [ $yr eq 0 ] then echo -n $yr is a leap year else echo -n $yr is not a leap year. fi SAMPLE INPUT/OUTPUT: $sh leap.sh Enter a year: 1987 1987 is not a leap year

#Shell program to determine the grade based on marks: echo n Enter the mark read mark echo -n The student has secured : if [ $mark gt 90 ] then echo S grade elif [ $mark gt 80 ] then echo A grade elif [ $mark gt 70 ] then echo B grade elif [ $mark gt 60 ] then echo C grade elif [ $mark gt 55 ] then echo D grade elif [ $mark ge 50 ] then echo E grade else echo U grade fi SAMPLE INPUT/OUTPUT: $sh grade.sh Enter the mark:82 The student has secured B grade.

#Shell program to check whether the file exist or not: echo -n Enter a file name read fn if [ ! -f $fn ] then echo -n The given file does not exist else cat $fn fi SAMPLE INPUT/OUTPUT: $sh file.sh Enter a file name: year.sh The given file does not exist.

#Shell program for employee pay calculation: echo n Enter the basic salary : read basic if [ $basic gt 30000 ] then HRA = `expr 5 \* $basic / 100` DA = `expr 5 \* $basic / 100` Tax = `expr 10 \* $basic / 100` elif [ $basic gt 20000 ] then HRA = `expr 4 \* $basic / 100` DA = `expr 3 \* $basic / 100` Tax = `expr 8 \* $basic / 100` else HRA = `expr 3 \* $basic / 100` DA = `expr 2 \* $basic / 100` Tax = `expr 5 \* $basic / 100` Gross = `expr $basic + $DA + $HRA` Net = `expr $Gross - $Tax fi echo $net is the net salary. SAMPLE INPUT/OUTPUT: $sh basic.sh Enter the basic salary : 10000 10000 is the net salary.

#Shell Program for temperature conversion : echo -n "Enter the Celsius value : " read cel #conversion of celsius to fahrenheit f = `expr $cel \* 1.8 + 32 | bc` echo -n "The equivalent Fahrenheit value is : " $f #conversion of fahrenheit to celsius echo "Enter the fahrenheit value : " read fah c=`expr ($fah - 32) / 1.8` echo -n "The equivalent Celsius value is : " $c SAMPLE INPUT/OUTPUT: $sh temp.sh Enter the Celsius value : The equivalent Fahrenheit value is : Enter the fahrenheit value : The equivalent Celsius value is :

Das könnte Ihnen auch gefallen