Enter a very long command at shell. Now continue to up-arrow into history, tweak it, and make it a lot longer. At some point you're thinking: "I should have made this a multi-line command when I started". Well, now that the command is all just one line, is there a way to break it up?
Example:
foo | grep "aaaaaaaaaaaaaaaaaa" | grep "bbbbbbbbbbbbbb" | more
Now to make that easier to continue editing:
foo |\ << enter some control character here to split the line
grep "aaaaaaaaaaaaaaaaaa" |\
grep "bbbbbbbbbbbbbb" |\
more
In the above example, it wouldn't work to position the cursor after the pipe, enter backslash, then Ctrl+Enter. Nor Shift+Enter, Ctrl+N, etc. Depending on the keystroke a new line does open with >
, but it appears to be waiting for text which would follow the last character ( more
above, rather than foo |
).
The old fashioned way to get out of this situation is to copy the line (using the mouse or from .history
), paste it into an editor, break it up and add the \
EOL on each line, then copy/paste it back into the CLI. That's ugly-primitive.
Is there an easier way to break up a long line of multiple commands in the terminal?