0

For an assignment, I'm trying to make a shell script that will print a triangle that looks like the following:

+
| \
|  \
|   \
|    \
+-----

Here is my code in VIM:

echo'+
     | \
     |  \
     |   \
     |    \
     +----- '

However, instead of getting that as the output when I run the script, it outputs as the following:

VI output issue

Can anybody tell me what I'm doing wrong?

nobody
  • 19,814
  • 17
  • 56
  • 77
sodhosdh
  • 25
  • 4
  • Do you really not have a space after `echo`? You should be getting an error message from that. – Barmar Jun 10 '16 at 23:53

2 Answers2

0

Try this

#!/bin/bash
echo '
     +
     | \
     |  \
     |   \
     |    \
     +----- '

just start it on the next line since you need spaces before the "+"

Nungster
  • 726
  • 8
  • 28
  • Oh my God. It's always the little things like that which kill me in programming. That did the trick! Thanks! – sodhosdh Jun 10 '16 at 23:40
0

How did your output got merged to 3 lines?
I think your original command was with a space after echo and double quotes:

echo "+
     | \
     |  \
     |   \
     |    \
     +----- "

And now pay attention to the last character of each line. When the last character is the \, the following line is appended to the current line.
Make sure each line ends with a space (or use single quotes).

Walter A
  • 19,067
  • 2
  • 23
  • 43