shell program examples
#!/bin/bash
#VR Tech Tips
#Write a script that accept number #from command
#line and check the numbers are ODD #or EVEN between
#1 to N numbers. Put appropriate #validation on command line.
echo "Enter the value : "
read a
while [ $a -eq 0 ]
do
if [ `expr $a % 2 ` -eq 0 ]
then
echo "Even $a"
else
echo "Odd $a"
fi
a=`expr $a - 1`
done
#!/bin/bash
#VR Tech Tips
#Write script to print given numbers #sum of all digit, For eg. If no is #123 it's
#sum of all digit will be 1+2+3 = 6.
echo "Enter Number : "
read a
tmp=$a
r=1
v=0
while [ $tmp -ne 0 ]
do
r=`expr $tmp % 10 `
tmp=`expr $tmp / 10 `
v=`expr $r + $v `
done
echo "Toatal Even Number is :-> $v"
No comments:
Post a Comment