Skip to content

Instantly share code, notes, and snippets.

@0xAether
Created July 28, 2012 20:14
Show Gist options
  • Save 0xAether/3194638 to your computer and use it in GitHub Desktop.
Save 0xAether/3194638 to your computer and use it in GitHub Desktop.
Prints an inverted pyramid.
#!/usr/bin/env bash
#
# Inverted Pyramid
# By: Aaron
# Date: July 28, 2012
#
# This script will only accept one argument that should be a number.
# It will print an upside down pyramid that starts at the nearest odd number to the one you provided.
#
# Screenshot: http://newroman.net/permalink/inverted_pyramid.png
#
if [ $# = 1 ]
then
num=$1
else
echo 'Need one argument'
exit 1
fi
if [ $num -le 1 ]
then
echo 'Number too small'
exit 1
else
:
fi
if [ `expr $num % 2` -eq 0 ]
then
num=`expr $num + 1`
else
:
fi
counter=0
while [ $counter != $num ]
do
printf "*"
counter=`expr $counter + 1`
done
printf "\n"
counter=0
spaces=1
while [ $num -gt 1 ]
do
while [ $spaces != $counter ]
do
printf " "
counter=`expr $counter + 1`
done
num=`expr $num - 2`
counter=0
while [ $num != $counter ]
do
printf "*"
counter=`expr $counter + 1`
done
printf "\n"
counter=0
spaces=`expr $spaces + 1`
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment