4. Write a shell program to show Arithmetic Operation.
Solution :
echo "Enter first number "
read num1 echo "Enter second number" read num2 sum=$(( $num1 + $num2 )) echo "Addition of $num1 and $num2 = $sum" sub=$(( $num1 - $num2 )) echo "Substraction of $num1 and $num2 = $sub" mul=$(( $num1 * $num2 )) echo "Multiplication of $num1 and $num2 = $mul" div=$(( $num1 / $num2 )) echo "Division of $num1 by $num2 = $div" mod=$(( $num1 % $num2 )) echo "Modulus of $num1 and $num2 = $mod" 5. Write a shell program to show Relational Operation using Alphabetical Symbol. Solution :
echo "Enter a number "
read a echo "Enter another number " read b if [ $a -eq $b ] then echo "$a -eq $b : a is equal to b" else echo "$a -eq $b : a is not equal to b" fi if [ $a -ne $b ] then echo "$a -ne $b : a is not equal to b" else echo "$a -ne $b : a is equal to b" fi if [ $a -gt $b ] then echo "$a -gt $b : a is greater than b" else echo "$a -gt $b : a is not greater than b" fi if [ $a -lt $b ] then echo "$a -lt $b : a is less than b" else echo "$a -lt $b : a is not less than b" fi if [ $a -ge $b ] then echo "$a -ge $b : a is greater than equal to b" else echo "$a -ge $b : a is not greater than equal to b" fi if [ $a -le $b ] then echo "$a -le $b : a is less than equal to b" else echo "$a -eq $b : a is not less than equal to b" fi 6. Write a shell program to show Relational Operation using Alphabetical Symbol. Solution :
echo "Enter a : "
read a echo "Enter b : " read b if (( $a == $b )) then echo "a is equal to b" else echo "a is not equal to b" fi if (( $a != $b )) then echo "a is not equal to b" else echo "a is equal to b" fi if (( $a > $b )) then echo "a is greater than b" else echo "a is not greater than b" fi if (( $a < $b )) then echo "a is less than b" else echo "a is not less than b" fi if (( $a >= $b )) then echo "a is greater than equal to b" else echo "a is not greater than equal to b" fi if (( $a <= $b )) then echo "a is less than equal to b" else echo "a is not less than equal to b" fi 7. Write a shell program to show Boolean Operation. Solution :
echo "Enter first number:"
read a echo "Enter Second number:" read b if [ $a != $b ] then echo "$a != $b : return true" else echo "$a != $b : return false" fi if [ $a -lt 100 -a $b -gt 50 ] then echo "$a -a $b : return true" else echo "$a -a $b : return false" fi if [ $a -lt 200 -o $b -gt 500 ] then echo "$a -o $b : return true" else echo "$a -o $b : return false" fi 8. Write a shell program to show File Test Operator. Solution :
echo "Enter the file name "
read fn if [ -e $fn ] then echo "$fn file is found." else echo "$fn file is not found." fi if [ -r $fn ] then echo "$fn file has read access." else echo "$fn file has not read access." fi if [ -s $fn ] then echo "$fn file is not emtpy." else echo "$fn file is empty." fi if [ -w $fn ] then echo "$fn file has write access." else echo "$fn file has not write access." fi if [ -x $fn ] then echo "$fn file has execution access." else echo "$fn file has not execution access." fi
Real Time Systems and Programming Languages Ada 95 Real Time Java and Real Time POSIX 3rd Edition by Alan Burns, Andy Wellings ISBN 0201729881 9780201729887 - Download the entire ebook instantly and explore every detail