#!/bin/bash
# Usage: script.sh number
# A for loop example produces following output
#
# *
# * *
# * * *
# * * * *
# * * * * *
#
Method1
c=1
n=$1
echo -e "\033[47m\c" #colourizing output
for ((row=1;row<=n;row++))
do
for ((i=row;i<n;i++))
do
echo -n ' '
done
for ((k=1;k<=c;k++))
do
if [ $((k%2)) -eq 0 ]
then
echo -n " "
else
echo -e "\033[43m * \033[47m\c"
fi
done
for ((i=row;i<n;i++))
do
echo -n ' '
done
c=$((c+2))
echo
done
echo -e "\033[0m" #Restoring colours
unset c i k n row
Method2
#!/bin/bash
n=$1
t=$((2*n - 1 ))
a=$n
b=$((a+1))
echo -e -n "\033[47m"
for (( i=1 ; i<=$n ;i++ ))
do
a=$(($b-1))
b=$a
k=1
for (( j=1 ; j<=$t ; j++ ))
do
if [ $j -eq $a ]
then
echo -e "\033[43m * \033[47m\c"
if [ $k -lt $i ]
then
a=$((a+2))
let k++
fi
else
echo -n " "
fi
done
echo
done
echo -e "\033[0m"
Output:Wednesday, October 7, 2009
Posted by venu k
4 comments | 8:19 AM
Subscribe to:
Post Comments (Atom)
Thanks! This article was very helpful and saved me many hours of digging and experimentation.
ReplyDeleteThank you for sharing this post. I appreciate it.
ReplyDeleteYou have shared nice post.
ReplyDeleteThe post is written in very a good manner and it contains many useful information for me :
ReplyDeleteobat anyang anyangan
obat benjolan di belakang telinga
obat usus buntu
obat mata ikan di telapak kaki
obat tumor rahim
obat penghilang lipoma
obat patah tulang