How can I output a multipline string in Bash without using multiple echo calls like so:
echo \"usage: up [--level | -n ][--help][--version
Use -e
option, then you can print new line character with \n
in the string.
Sample (but not sure whether a good one or not)
The fun thing is that -e
option is not documented in MacOS's man page while still usable. It is documented in the man page of Linux.
Use the -e argument and the escape character \n:
echo -e "This will generate a next line \nThis new line is the result"
If you use the solution from @jorge and find that everything is on the same line, make sure you enclose the variable in quotes:
echo $__usage
will print everything on one line whereas
echo "$__usage"
will retain the newlines.