4

If I unintentionally add a newline in a command, as far as I can tell, the only way to undo it is to press Ctrl+c and type the command again. For example:

$ cat 'John's File'
> ^C
$ cat "John's File"

This is annoying if the original command is long.

Is there a way to delete the newline and remove the > prompt so that I can go back to the original command?

  • 2
    Press KeyUp? This works for me with bash3. No newline even if it was in my X11 clipboard. What effects do you run into? – user140866 Nov 8 '15 at 17:47
  • I don't really want my history littered with partial commands. – EmmaV Nov 8 '15 at 18:08
  • Ah, got that you want to get rid of > and return back without pressing Ctrl-C, sorry misunderstood. I don't really know, it enters new mode in which it waits from you to complete typed command because it's incomplete. I usually do KeyUp after Ctrl-C/D if there is a mistake and fix it. The whole command appears intact after I press KeyUp. – user140866 Nov 8 '15 at 18:13
1

Is there a way to delete the newline ... ?

Actually: No. But there are excellent workarounds.

As you have already introduced an Enter, the line has been stored in the list of commands executed. Press ControlC to get out of the command, then, without re-typing, press up-arrow. The command entered appears again, and could be edited.

2

From man bash

       edit-and-execute-command (C-xC-e)
          Invoke an editor on the current command line, and execute the result as shell commands.  Bash attempts to invoke $VISUAL, $EDITOR, and emacs as the editor, in that order.
  • This doesn't work. After editing and saving the temp file, the command is executed properly, but I'm left back at the > prompt. – EmmaV Nov 9 '15 at 18:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.