In sh (not Bash), how would we abort execution of command when the prompt is in > mode?

For example, when entering a string with quotes only at the beginning, it makes the prompt look like >, without the ability to quit it normally, unless hitting Ctrl + D. Example:

root@MyPC:~# echo "hello
> I am
> (How do I exit of this mode?)

In case that I don't know which character delimits the string (" or ' or simply escaping a newline/spaces with backslash), is there a way to let Bash know that I want to abort the execution of the current command?


^C aka Ctrl+C will abort what you're doing and get you back to a normal prompt.

  • 2
    A good thing to know in general for interrupting any running command. – orion Mar 5 '14 at 10:09
  • if it does not work try also crtl + d to stop process and if does not work use ctrl + z to background the running command find it's PID and kill it with kill – Kiwy Mar 5 '14 at 10:54
  • ^D will only work if a process is reading from standard input. ^\ is a good one too (sends a SIGQUIT). – Flup Mar 5 '14 at 11:01
  • 2
    @Kiwy Easier is to run jobs and use kill %x – Bernhard Mar 5 '14 at 12:19
  • 1
    It depends what intr is set to on the tty. If you do stty -a you'll see which control codes are set to do what. – Flup Mar 5 '14 at 15:32

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.