Reputation: 13433
In a Linux terminal, how can a newline (line feed?) be added without issuing a carriage return/issuing the command?
For example, in my case, I'd like to add several lines to a git commit comment, like so:
$ git commit -m "1. Removed comment blocks
2. updated .gitignore
3. added goto statement to hander
--Miklas"
How do I add these line feeds for a multiple-line comment without actually entering the command?
I've googled around and tried a number of things (shift+return, alt+return, ctrl+return.. etc), but no luck. Tyvm Keith :^)
Upvotes: 1
Views: 869
Reputation: 140880
Shells generally come with a support of multiline continuation of commands. If shell "detects" that the previous command is not "complete" and you typed enter, it will print PS2
and let you continue inputting a command. Default PS2="> "
.
# I type:
# git commit -m "message<enter><enter>description"<enter>
$ git commit -m "message
>
> description"
no changes added to commit
It works also for with shell operators, like for
, while
, if
, case
:
$ for i in 1 2 3
> do
> echo $i
> done
1
2
3
I found a youtube video that shows the behavior.
You may also use C-ish quoting in bash:
git commit -m $'message\n\ndescription\n'
I sometimes use process subtitution with printf
:
git commit -m "$(printf "%s\n" "message" "" "description")"
And finally you may type just:
git commit
that should open a full file editor, by default vim
. In that editor type the multiline message you want, save and quit the editor and the file content will be taken as the commit message.
Upvotes: 2