Pgms
Pgms
FRUIT="kiwi" case "$FRUIT" in "apple") echo "Apple pie is quite tasty." ;; "banana") echo "I like banana nut bread." ;; "kiwi") echo "New Zealand is famous for kiwi." ;; esac
vowels
echo 'Give a word' read word case $word in a*|e*|i*|o*|u*) vowels=&((klinker + 1 )) ;; *) consonants=&((medeklinker + 1 )) ;; esac echo $vowels echo $consonants word=abstemiously vowels=$(echo $word | sed 's/[^aeiou]//g') echo "${#vowels} vowels"
SI
echo " Enter the principle value: " read p echo " Enter the rate of interest:" read r echo " Enter the time period:" read t s=`expr $p \* $t \* $r / 100` echo " The simple interest is " echo $s
SAWP
echo read echo read echo z=$x x=$y y=$z echo "Enter value for x : " x "Enter value for y : " y "Before swap, x = $x and y = $y"
LEAP YEAR
Echo -n Enter the year(yyyy) to find leap year :- Read year d = `expr $year % 4` b = `expr $year % 100` c = `expr $year % 400` if [ $d -eq 0 -a $b -ne 0 -o $c -eq 0 ] then Echo year is leap year else Echo not leap year fi
ODD or EVEN
echo -n "Enter numnber : " read n rem=$(( $n % 2 )) if [ $rem -eq 0 ] then echo "$n is even number" else echo "$n is odd number" fi
Positive or Negative
if [ $1 -gt 0 echo "$1 is elif [ $1 -lt then echo "$1 is elif [ $1 -eq then echo "$1 is else echo "Opps! fi
echo -n "Enter number : " read n sd=0 sum=0 while [ $n -gt 0 ] do sd=$(( $n % 10 )) # get n=$(( $n / 10 )) # get sum=$(( $sum + $sd )) # done echo "Sum of all digit is
Code for Write a shell program to find the gcd for the 2 given numbers in Unix / Linux
echo Enter two numbers with space in between read a b m=$a if [ $b -lt $m ] then m=$b fi while [ $m -ne 0 ] do x=`expr $a % $m` y=`expr $b % $m` if [ $x -eq 0 -a $y -eq 0 ] then echo gcd of $a and $b is $m break fi m=`expr $m - 1` done
DIvisible by 5 or not
echo "Enter a number" read number if [ $(( $number % 5 )) -eq 0 ] ; then
echo "Your number is divisible by 5" else echo "Your number is not divisible by 5" fi
q&r echo program for Q & R echo Enter the first number read a echo Enter the second number read b quo=`expr $a / $b` rem=`expr $a % $b` echo The quotient is:$quo
POWER OF X echo read echo read "Input number" no "Input power" power
counter=0 ans=1 while [ $power -ne $counter ] do ans=`expr $ans \* $no` counter=`expr $counter + 1` done echo "$no power of $power is $ans"
STUDENT GRADES echo "Enter the five subject marks for the student" read m1 m2 m3 m4 m5 sum1=`expr $m1 + $m2 + $m3 + $m4 + $m5` echo "Sum of 5 subjects are: " $sum1 per=`expr $sum1 / 5` echo " Percentage: " $per if [ $per -ge 60 ] then echo "You get Distinction elif [ $per -ge 50 ] then echo You get First class elif [ $per -ge 40 ] then echo "You get Second class" else echo "You get Fail" fi