Copy, paste, and edit multiline command in bash terminal
Commands with lots of arguments sometimes use slash escaped newlines to make them easier to read on the web. Here is a silly example
echo -n \
"hello" \
"world"
I'm not sure how to paste and edit this "properly"
Pasted into bash you get
$ echo -n \
> "hello" \
> "world"
Now if I navigate with the back arrow key on OSX, I can only edit the line with > "world"
, not the first two lines. Usually I have to paste into a temp file to fix up a command.
Is there a better way to perform this paste which allows editing any line? bash
setting which makes this work in a nicer way?
Solution 1:
When you have such a command on several lines you can, if you're using bash in emacs mode (usually the default one) ctrl+x ctrl+e
it will open your favorite editor, as specified in your EDITOR variable.
Or you can type fc
, this will open the editor on the last command you've typed, then you can edit it as you want, then feel free to quit, and it will be executed.