79561956

Date: 2025-04-08 12:06:49
Score: 0.5
Natty:
Report link

The following worked on the default Ubuntu (24.04.1) terminal using bash as the shell interpreter.

The Ctrl-V solution

This is the "what you see is what you get" (WYSIWYG) solution that I think you're looking for since you mentioned trying "shift+return, alt+return, ctrl+return.. etc".

Just try Ctrl+V followed by Ctrl+J to get a new line on your terminal.

This should place the cursor on your terminal at the beginning of a new line allowing you to continue introducing text inside your double quoting just like your example shows (an actual multiline block of text as if you're inside a text editor). That combination will pass the equivalent of a line feed character ('\n') to the command.

$ echo "line1
line2
line3" >multiline_from_ctrlvj
$ cat multiline_from_ctrlvj 
line1
line2
line3
$

Related to this, entering Ctrl+V followed by TAB will "print" a tabulation on your terminal and send a '\t' character to the shell

$ echo "one    two     three   four"
one two three   four
$

Entering Ctrl+V followed by ENTER will print a '^M' on your terminal but will send a carriage return to the shell":

$ echo "this will be overwritten by^MTHIS"
THIS will be overwritten by
$

The ANSI C quoting solution

(already pointed out by @KamilCuk)

If you don't care about how your terminal looks like while typing but just want to insert the newline as part of the argument string, you can always use the ANSI C quoting style as an alternative to the double quoting. The ANSI C quoting style requires a leading $ sign and simple quotes:

$'any text including ANSI C special characters such as '\n' or others'

$ echo $'line1\nline2' >multiline_from_ANSI_C_quoting
$ cat multiline_from_ANSI_C_quoting 
line1
line2
$

Notice that the $'...' quoting must be used instead double quoting "...", since something like this won't work as desired (double quoting removes the special meaning of the $ sign for the shell):

$ echo "line1$'\n'line2"
line1$'\n'line2
$

The command substitution solution

(already pointed out by @KamilCuk)

Whatever you put inside $(...) gets executed in a subshell and its output (not exactly but irrelevant here) is used to replace the entire $(...)construction. That is why this is also an option:

git commit -m "$(printf "%s\n" "message" "" "description")"

Notice that any double quoting inside $(...) doesn't affect the outer double quoting.

PD: The recommended way to commit

A well documented commit should have a title (single short line) and a body (multiline block). When you use the git commit -m "brief title of the commit" you're just attaching a title to the commit while leaving its body empty. As pointed out by @KamilCuk, you should have your git configured to use a text editor (such as vim). If that's the case, entering just git commit will open the text editor where you must: 1) enter the first line as the commit title; 2) leave the second line empty; 3) start your commit detailed multiline description from the third line; 4) save and quit the text editor; then the commit will be done.

Check your .gitconfig file for something like this to confirm if you have an associated text editor for git:

[core]
    editor = vim

Execute something like this to configure a text editor for git:

$ git config --global core.editor "vim"
Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @KamilCuk
  • User mentioned (0): @KamilCuk
  • User mentioned (0): @KamilCuk
  • Low reputation (1):
Posted by: Luis Luque