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:
Can anybody tell me what I'm doing wrong?
Try this
#!/bin/bash
echo '
+
| \
| \
| \
| \
+----- '
just start it on the next line since you need spaces before the "+"
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).