Crazy Dots

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

  1. The problem statement, all variables and given/known data:

Create a script called DOTS that will display the horizontal or vertical number of dots if the first argument entered after the dots command will be h or v.

ust use the while statement.

  1. The attempts at a solution (include all code and scripts):
# Hello
dot=0

while [ $1 -eq "h" -a $dot -lt $2 ]
do
   echo "."
   dot=`expr $dot + 1`
done
~

This is the error wnen I run the command:

n0-greg@conted:~$ ./dots2 h 6
./dots2: line 4: [: h: integer expression expected
n0-greg@conted:~$ ./dots2 h 6
  1. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
    John Abbott College, Montreal QC, CANADA, Oswaldo Moreno, Operating Systems UNIX. There is no direct link to the course itself.

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

You are very very close.

"-eq" is for integers only, for strings use =

To handle both "h" (horizontal dots) and "v" (vertical dots) in the same script you will need to change the structure of the script slightly bearing in mind the previous post about the different ways of comparing strings and integers.

A script becomes easier to read if we save the input parameters to named variables early in the script.

For example:

if [ $# -ne 2 ]
then
    echo "Usage: `basename $0` [h|v] dot_count"
    exit
fi
#
dot=0
orientation="$1"
dot_count=$2

while [ ${dot} -lt ${dot_count} ]
do
   # Horizontal
   if [ "${orientation}" = "h" ]
   then
       printf "."       # No linefeed
   fi
   # Vertical
   if [ "${orientation}" = "v" ]
   then
       printf ".\n"     # With linefeed
   fi
   #
   dot=`expr $dot + 1`
done
#
if [ "${orientation}" = "h" ]
then
   printf "\n"  # End the horizontal dots with a linefeed
fi

Thanks a lot!