Shell Program - pattern 3

        *
      **
    ***
  ****
*****


CODE:

#! /bin/bash
echo "enter number of lines:"
read n
for((i=1;i<=n;i++))
do
  for((j=1;j<=n-i;j++))
  do
    echo -ne " "
  done

Shell Program - pattern 2

*
**
***
****
*****

CODE:

#! /bin/bash
echo "enter number of lines:"
read n
for((i=1;i<=n;i++))
do
  for((j=1;j<=i;j++))
  do

Shell Program - Pattern 1

1
11
111
1111
11111

CODE: 

echo "enter number of lines:"
read n
for((i=1;i<=n;i++))
do
for((j=1;j<=i;j++))
do
    echo -ne "1"

Shell Program - Multiplication table of the given number

CODE:

#! /bin/bash

echo "enter the number:"
read a

echo "Multiplication table"

for((i=1;i<=10;i++))
do
echo "$a * $i = `expr $a \* $i`"

Shell program - to find sum and average of three numbers

CODE:

#! /bin/bash

echo "enter three numbers"
read a
read b
read c
sum=`expr "$a" + "$b" + "$c"`
avg=`expr "$sum" \/ 3 ` 
echo "sum="$sum

Shell Program - to find square and cube of the given number

CODE:

#! /bin/bash

echo "enter a number:"
read a
sq=`expr "$a" \* "$a" `
cube=`expr "$a" \* "$a" \* "$a" `
echo "The square of $a =" $sq
echo "The cube of $a=" $cube


OUTPUT:
Shell Program - to find square and cube of the given number

Shell Program - to print natural numbers upto n

CODE:

#! /bin/bash

echo "enter the value of n:"
read n
for((i=1;i<=n;i++))
do
echo " $i"

done

OUTPUT:
Shell Program - to print natural numbers upto n

Shell Program - Check whether the given number is even or odd.

CODE:

 #! /bin/bash

echo "Enter a number"
read a
if test `expr $a % 2` -eq 0
then
echo "$a is even number"
else
echo "$a is odd number"
fi


OUTPUT:
Shell Program - Check whether the given number is even or odd.

Shell program - swapping of two numbers without using third variable

CODE:

#! /bin/bash

echo "enter two numbers:"
read a
read b
c=`expr "$a" - "$b" `

echo "$a - $b ="$c

OUTPUT:

Shell program - swapping of two numbers without using third variable

Shell program - swapping of two numbers using third variable

CODE:

#! /bin/bash

echo "enter two numbers:"
read a
read b
echo "Before swapping, a=$a and b=$b"
z=$a
a=$b
b=$z

echo "After swapping, a=$a and b=$b"

OUTPUT:
Shell program - swapping of two numbers using third variable

Shell program - Division of two numbers

CODE:

#! /bin/bash

echo "enter two numbers:"
read a
read b
c=`expr "$a" \/ "$b" `

echo "$a / $b ="$c


OUTPUT:

Shell program - Division of two numbers

Shell program - Multiplication of two numbers

CODE:

#! /bin/bash

echo "enter two numbers:"
read a
read b
c=`expr "$a" \* "$b" `

echo "$a * $b ="$c


OUTPUT:

Shell program - Multiplication of two numbers

Shell program - Subtraction of two numbers

CODE:

#! /bin/bash

echo "enter two numbers:"
read a
read b
c=`expr "$a" - "$b" `

echo "$a - $b ="$c

OUTPUT:

Shell program - Subtraction of two numbers


Shell program - Addition of two numbers

CODE:

#! /bin/bash

echo "enter two numbers:"
read a
read b
c=`expr "$a" + "$b" `

echo "$a + $b ="$c

OUTPUT:

Shell program - Addition of two numbers