Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

So tab completion is great... unless you're a n00b... and you type the first part of ifconfig and then hit tabenter real quick... in which case you end up with:

(not actual terminal input)

~$ if
> 
> 
>'
> "
> end
> ^C
> 
> )
> ()
> ]
> 
> []
> ]
> ;
> 
> 
> []
> ;aognf'
> 
> 

What's really weird is ctrlc didn't even work. I know about quotation marks (which is why that's what I tried first), but that knowledge didn't help.

How can I break out of one of these fat-fingered mistakes next time, without closing the terminal?

Bonus point for answering what is this thing that I've accidentally started doing?

share|improve this question
    
Is this the stock Unity terminal? Ctrl+C works for me too. –  Sparhawk Mar 13 at 23:39
    
Yup, it's stock. And ^C has worked every other time I've tried. My theory is that I'd somehow created a sequence in the if statement that escaped or ignored the ^C. Subsequent trials with if statements in the terminal have all successfully aborted with ^C. –  mHurley Mar 14 at 14:31
    
Very interesting, actually! I took you literally, and typed out the above lines, but I suppose you were paraphrasing then. –  Sparhawk Mar 15 at 0:46
    
Yeah, that's just a representative sample... sort of ;-) –  mHurley Mar 17 at 19:09

3 Answers 3

up vote 1 down vote accepted

You have started an if statement. The next command is run, and only if it returns a zero exit status ( success ) are the following commands executed up until the fi statement ( if backwards ). Like:

if true
    echo yes
fi

Typically one uses the test program, otherwise known as [ to test various things such as:

if [ $somevariable = someword ]

or

if [ -f /some/file/exists ]

A ctrl-c aborts it fine for me.

share|improve this answer
    
hmm, ctrl-c definitely didn't work for me, and I saw fi elsewhere and tried that too, but none of that returned me to the command prompt. I wouldn't be surprised if my subsequent button-mashing got me into a slightly more complex set of nested brackets and quotes than I thought... Now I know what to try next time, though ;-) Thanks! –  mHurley Mar 13 at 2:54

Use Control-D in cases like this.

You've gotten stuck in a bash shell if conditional control structure.

This is the output I see:

$ if
> 
> '
> "
> sdf
> )
> []

Control-D

bash: syntax error: unexpected end of file

share|improve this answer

Use stty -a to be sure that intr = ^C. If it isn't, ^C is just another character. stty sane helps me out of terminal confusion. See man stty. Here is the first few lines of mine (where ^C does interrupt if....):

walt@spong:~(0)$ stty -a
speed 38400 baud; rows 24; columns 80; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = M-^?; eol2 = M-^?;
swtch = M-^?; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W;
...
share|improve this answer
    
Nice idea. mHurley, you could also check if ctrl+C works but typing in a facile command (e.g. echo foo), then typing ctrl+C. –  Sparhawk Mar 13 at 23:45
    
Yes, ^C works and has worked for all other things (that weren't otherwise unresponsive), it just didn't in this case. My theory is that I'd accidentally created a sequence in the if statement that escaped or ignored the ^C. Subsequent trials with if statements in the terminal have all successfully aborted with ^C. –  mHurley Mar 14 at 14:29

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.