Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 10 down vote accepted

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

share|improve this answer
2  
A good thing to know in general for interrupting any running command. –  orion Mar 5 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 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 at 11:01
2  
@Kiwy Easier is to run jobs and use kill %x –  Bernhard Mar 5 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 at 15:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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