I don't know how many of you have encountered this, but I find it interesting. Maybe also because I do not totally know what the "echo" command can do. If anyone has the interest and nerves to give me a couple of reasons for this I would be most grateful.

Playing is learning and I must ask you to check with your terminal first: What is the output of the command echo !T in your terminal?

Here is what the terminal shows me as an output:

echo They are 9 in the fellowship
They are 9 in the fellowship

The terminal I am playing with is using the default bash shell, on Ubuntu 12.04.3 LTS. What does "!T" stand for in the "echo" command?

  • This is a Q&A site. What are you actually asking? – kiri Feb 14 '14 at 23:43
  • I forgot to stress the question, thank you for pointing that out :) – Nooby Feb 15 '14 at 0:07
  • No, I listed everything. No matter which is the directory I work in, the output is the same. And this is what I found quite intriguing :-?? ...and awesome as I recently watched LOTR :)) – Nooby Feb 15 '14 at 0:11

!T is not related to echo but is replaced by bash before echo can see it.

A ! that is not followed by a white space character or = starts history substitution. That is it gets replaced with the most recent command in the hostory list that starts with what follows the !.

So !T gets replaced with the most recent command you entered that starts with a T.

echo then just outputs that.

  • Tried it and it makes sense x_X ...though I did not know about that :| Thank you! – Nooby Feb 15 '14 at 0:23
  • Note that the sequence !! gets replaced with the last command entered. This is especially useful when you forgot to use sudo, just type sudo !! to run last command with superuser privileges. (Could be used to avoid repetition, for example: xkcd.com/149) – Hannes Karppila Mar 15 '16 at 23:12

While you are learning/playing in cli (command line interface), you can use man to get a synopsis of what the command is and what options are available. Basically, echo just outputs text to the screen. I have seen it used to pipe (|) data into/from files. Good luck!

  • I have quite some material to cover until piping. I looked over the man page of echo, but none seem to suggest such thing :| Normally I think the output of "echo !T" should actually be "!T". Have you tried it and ran as expected? – Nooby Feb 15 '14 at 0:17
  • I get the following: bash: !T: event not found. So, apparently the !T is a variable set in your environment. – skjennings Feb 15 '14 at 0:21
  • One thing you could do is start a new terminal session and run the command. If you get the output from above then most likely you set T to that string in the other session; otherwise the T variable is being set in your user preferences. – skjennings Feb 15 '14 at 0:38
  • Closed and started Terminal several times. Could you introduce me into the world of clearing its history? :)) – Nooby Feb 15 '14 at 0:40
  • If you closed/open then you started a new session. CTRL-Shift-T is a new tab (like FF), CTRL-SHIFT-N creates a new session. So, I'm guessing its something in your user profile and/or environment. You can type env to see your environment settings – skjennings Feb 15 '14 at 1:10

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.