[SLUG] If there's a competition for the most useless bash script...

Al Girling al21 at firenet.uk.com
Tue Apr 22 23:11:01 BST 2003


On Mon, 21 Apr 2003 00:21:15 +0100
Jonathan Worthington wrote:

> Hi,
> 
> Well, here's my first effort at a bash script.  It draws a rectangle and
> calculates its area.  Maybe one day I'll aspire to something more useful.
> ;-)
> 
> #!/bin/bash
> # Rectangle drawing script.  Takes three parameters:-
> #  ./rectangle.sh length width [chracater]
> # Where character is the character used to print the rectangle.
> # If no character is entered, a # is used.
> # #####################################################################
> 
> # Assign input.
> LENGTH=$1
> WIDTH=$2
> CHAR=$3
> 
> # If no char is entered set it to default (#).
> if [ -n $CHAR ]; then
>      CHAR='#'
> fi
> 
> # Print a blank line.
> echo
> 
> # Draw rectangle.
> CURWID=0
> while [ $CURWID -lt $WIDTH ]; do
>      CURLEN=0
>      while [ $CURLEN -lt $LENGTH ]; do
>           printf "$CHAR"
>           CURLEN=$((++CURLEN))
>      done
>      printf "\n"
>      CURWID=$((++CURWID))
> done
> 
> # Print area.
> printf "\nThe area of the rectangle is $[WIDTH*LENGTH].\n\n"
> 
> ###
> 
> Suggestions for optimisations welcomed!
> 
> Jonathan

Hi Jonathon,

I've just tried your script.  Works well with one exception.  I can't get it to use any symbol other than the default #.  I copied and pasted your script so it shouldn't be because of a typo.  Any ideas?

Al




More information about the Scarborough mailing list