Linux Shell Programming Star Patterns

                                                         Shell Script Program To Print Star Pattern


//Here 1-9 patterns logic are written look in the picture for the pattern you want to print and
//copy logic under pattern_1-9.

Q Commands used to execute ?
Ans: first go to desktop create a empty document pattern1.sh
copy the logic and then on terminal use the following commands.
this document must be in directory where you are working.
$chmod 777 pattern1.sh
$ ./pattern.sh
















pattern1

read num

for((i=1;i<=num;i++))

do

for((j=1;j<=i;j++))

do
echo -n "*"

done

echo " "

done




pattern2

read num

for((i=1;i<=num;i++))

do

for((j=1;j<=num-i+1;j++))

do

echo -n "*"

done

echo " "

done




pattern3

read num

for((i=1;i<=num;i++))

do

for((k=1;k<i;k++))

do

echo -n " "

done

for((j=1;j<=num-i+1;j++))

do

echo -n "* "

done

echo " "

done




pattern4

read num

for((i=1;i<=num;i++))

do

for((k=1;k<i;k++))

do

echo -n " "

done

for((j=1;j<=num-i+1;j++))

do

echo -n "*"

done

echo " "

done




pattern5

read num

for((i=1;i<=num;i++))

do

for((k=1;k<=num-i;k++))

do

echo -n " "

done

for((j=1;j<=i;j++))

do

echo -n "*"

done

echo
done




pattern6

read num

for((i=1;i<=num;i++))

do

for((k=1;k<=num-i;k++))

do

echo -n " "
done

for((j=1;j<=i;j++))

do

echo -n "* "
done

echo " "

done




pattern7

read num

for((i=1;i<=num;i++))

do

for((j=1;j<=i;j++))

do

echo -n "$i"

done

echo " "

done




pattern8

read num

for((i=1;i<=num;i++))

do

for((j=1;j<=i;j++))

do

echo -n "$j"

done

echo " "

done




pattern9

read num

for((i=1;i<=num;i++))

do

for((k=1;k<=num-i;k++))

do

echo -n " "

done

for((j=1;j<=2\*i-1;j++))

do

echo -n "*"

done

echo " "

done


1 comment: