To print asterisks based on inputs I have to print the number of stars that increases on each line from the minimum number until it reaches the maximum number, and then decreases until it goes back to the minimum number. After printing out the lines of stars, it should also print the total number of stars printed.

I have tried using shell scripting and worked. But is there any other simplified and generic way to achieve this. Or to be precise any better code to achieve this

echo "enter the mininum number of stars"
read min
echo "enter the maximum number of stars"
read max
for (( i=$min;i&lt;=$max;i++))
do
   for (( j=$max;j&gt;=i;j-- ))
   do
   echo -n " "
   done
   for (( c=1;c&lt;=i;c++ ))
   do
   echo -n " *"
   sum=`expr $sum + 1`
   done
echo ""
done
d_max=`expr $max - 1`
for (( i=$d_max;i&gt;=$min;i--))
do
   for (( j=i;j&lt;=$d_max;j++ ))
   do
   if [ $j -eq $d_max ]
   then
   echo -n " "
   fi
   echo -n " "
   done
   for (( c=1;c&lt;=i;c++ ))
   do
   echo -n " *"
   sum=`expr $sum + 1`
   done
echo ""
done
echo "Total No. of stars : "  $sum 


Output:    

      *
     * *
    * * *
   * * * *
  * * * * *
   * * * *
    * * *
     * *
      *
Shell programs should start with a shebang, so that when executed, the OS can select the correct interpreter:

#!/bin/bash


With Bash, we can read prompted input using read -p:

read -p "Enter the mininum number of stars: " min


We should check that we have a valid positive integer before using $min.

The same comments also apply to $max.  For both variables, consider accepting arguments instead of prompting for interactive input.

Prefer printf to echo -n - that's a good practice for portable scripting.

Most of those for loops can be eliminated with suitable printf formatting.  We can produce n stars with printf '%.${n}s' '' | tr ' ' '*', and we can put that into a space that's m wide, with printf '%${m}s' "$(printf '%.$ns' '' | tr ' ' '*')".  If we did keep the loops, we don't need $ for variable expansion within the arithmetic context (( )).

It seems strange to use arithmetic evaluation but also to invoke expr to increment $sum - it's more consistent to simply write ((++sum)).

The echo command with a single empty argument is equivalent to echo with no arguments, so no need to write "" there.