SHELL PROGRAMMING EXAMPLES

 1) Calculate Gretest Common Divisor (GCD) of two number echo "Enter the first number..." read n1 echo "Enter the second number..." read n2 if [ \$n1 -le \$n2 ] then while [ \$n1 -gt 0 ] do r=`expr \$n2 % \$n1` n2=\$n1 n1=\$r done echo "GCD = \$n2" else while [ \$n2 -gt 0 ] do r=`expr \$n1 % \$n2` n1=\$n2 n2=\$r done echo "GCD = \$n1" fi 2) Calculate Lowest Common Divisor (LCD) of two number echo "Enter the first number....." read n1 echo "Enter the second number....." read n2 n3=\$n1 n4=\$n2 if [ \$n1 -le \$n2 ] then while [ \$n1 -gt 0 ] do r=`expr \$n2 % \$n1` n2=\$n1 n1=\$r done n5=\$(( \$n2 * (\$n3 / \$n2) * (\$n4 / \$n2) )) echo "LCD = \$n5" else while [ \$n2 -gt 0 ] do r=`expr \$n1 % \$n2` n1=\$n2 n2=\$r done n5=\$(( \$n2 * (\$n3 / \$n2) * (\$n4 / \$n2) )) echo "LCD = \$n5" fi 3) Multiplication of two 3*3 Matrix # Input first matrix echo "Enter the element of array A" for((i=0;i<3;i++)) do for((j=0;j<3;j++)) do echo "enter the value of A[\$i][\$j]" read A[\$i][\$j] done done # Input second matrix echo "Enter the element of array B" for((i=0;i<3;i++)) do for((j=0;j<3;j++)) do echo "Enter the value of B[\$i][\$j]" read B[\$i][\$j] done done # Multiplication process for((k=0;k<3;k++)) do for((i=0;i<3;i++)) do for((j=0;j<3;j++)) do C[\$k][\$i]=\$((\${C[k][i]} + (\${A[k][j]} * \${B[j][i]}))) done done done # Print the multiplication result for((i=0;i<3;i++)) do for((j=0;j<3;j++)) do echo "C[\$i][\$j] = \${C[i][j]}" done done

QuestionSolves.com is an educational website that helps worldwide students in solving computer education related queries.

Also, different software like Visual Studio, SQL Server, Oracle etc. are available to download in different versions.

Moreover, QuestionSolves.com provides solutions to your questions and assignments also.

MORE TOPIC

WHAT WE DO