1

I sometimes manage to get my terminal messed up until I type "clear". This occurs in various ways, sometimes when writing individual commands, sometimes when editing something in a text editor. Now I have Mac OS X Lion, but I remember having this problem years ago even when I was still using Solaris.

Here's one case I managed to reproduce. If I make a mistake with cURL:

Bemmu-Sepponens-MacBook-Pro:b2 bemmu$ curl --data abcde=foo efghijk=bar http://localhost:1234/do_something_cool
curl: (6) Couldn't resolve host 'efghijk=bar'
foo Bemmu-Sepponens-MacBook-Pro:b2 bemmu$

Curl outputted "foo" and an error message. Now if I press the up arrow to return to edit that command, it first becomes like this:

Bemmu-Sepponens-MacBook-Pro:b2 bemmu$ curl --data abcde=foo efghijk=bar http://localhost:1234/do_something_cool
curl: (6) Couldn't resolve host 'efghijk=bar'
foo Bemmu-Sepponens-MacBook-Pro:b2 bemmu$ curl --data abcde=foo efghijk=bar http://localhost:1234/do_something_cool

Everything still looks OK, but notice the previous line was put after "foo" which came from cURL. Now if I try to press the left arrow enough times to get to the place where the error was and start typing, things become messed up:

foo Bemmu-Sepponens-MacBook-Pro:b2 bemmu$ curl --data abcde=foo&ijk=bar http://localhost:1234/do_something_cool

All I did was go to the place immediately after "abcde=foo " and press the backspace once and then put in an ampersand. It should have become "abcde=foo&fghijk=bar" but instead it became "abcde=foo&ijk=bar".

Is this normal, or do I have some setting wrong somewhere?

2 Answers 2

1

This is somewhat expected if the curl fails to output a newline after foo. You can try pressing ⌃C once before you press to edit your command.


Also note that you should escape your data string so the ampersand isn't interpreted as the command to run a job in background.

For example:

charon:~ werner$ curl --data abcde=foo&efghijk=bar http://localhost:3000/
[1] 96980
-bash: http://localhost:3000/: No such file or directory

The [1] indicates that a job was put in background, namely this one:

[1]+  Exit 2                  curl --data abcde=foo

So at the ampersand, your command was truncated. What you can do instead is this – escape the & with a backslash.

charon:~ werner$ curl --data abcde=foo\&efghijk=bar http://localhost:3000/

Alternatively, you can also put your data string into single quotes to prevent any expansion:

charon:~ werner$ curl --data 'abcde=foo&efghijk=bar' http://localhost:3000/
1
  • Hi, yes actually I knew about the ampersand problem and was just using that line as an example without checking if it really works.
    – Bemmu
    Mar 12, 2012 at 13:41
1

You can reset the terminal on OS X, and every other *nix I've been on, by typing:

echo ^V ESC c

in your terminal. ^V means "hold control and hit the `V' key", "ESC" is just hitting the escape key, and "c" is, obviously the "c" key.

What you're doing is having echo spit out the escape sequence.

^V means the next key you press (ESC, in this case) is put into the terminal verbatim (pressing ESC without it wouldn't do much), the following "c" is the actual code. You can get a full list here: http://ascii-table.com/ansi-escape-sequences-vt-100.php

This is a hard reset, so it'll fix just about any craziness your terminal may get itself into, although you might sometimes be typing blind.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .