6

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?

1

1 Answer 1

18

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

10
  • 2
    A good thing to know in general for interrupting any running command. Commented Mar 5, 2014 at 10:09
  • 2
    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 Commented Mar 5, 2014 at 10:54
  • ^D will only work if a process is reading from standard input. ^\ is a good one too (sends a SIGQUIT). Commented Mar 5, 2014 at 11:01
  • 2
    @Kiwy Easier is to run jobs and use kill %x Commented Mar 5, 2014 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. Commented Mar 5, 2014 at 15:32

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.