Simply quote it. Quoted strings can extend over multiple lines.
sh -c '
git status
echo "hello world"'
You can play with indentation and placement of the quotation marks to find out what most closely meets your aesthetic expectations.
# Does this look nicer?
sh -c '
git status
echo "hello world"
'
If you want variable expansion to take place, you'd probably want to change double and single quotes.
dir=/src/project/
sh -c "
cd $dir
git status
echo 'hello world'
"
Note that this becomes messy if you want more complex quoting (involving both, single and double quotes itself) in the -c
argument. Consider using heredoc syntax as suggested by Srdjan Grubor in this case. Note however that it feeds the script to the shell via standard input, not as a command line parameter.
For your second example, simply escape the newline character.
echo \
"hello world"
Be careful not to place any other spaces (or other characters, including comments) between the \
and the end of the line.
Some people, including me, find code easier to read if those backslashes are all aligned at some fixed column.
echo \
"hello" \
"happy" \
"fruit gum" \
"world"
Your editor might help you with this.