Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I was testing a script and wanted to create a small file with a bit of text in it so I typed the following and forgot to escape the space in the filename:

echo "bob">other name

When I did ls, it showed the file "other" and when I did cat other, it showed the contents as:

bob name

How did "name" get in the file? I believe I saw somewhere that you can put redirection anywhere in a command. In fact, I just tested this:

echo >other Some text in a file

and "Some text in a file" was the contents of "other".

What is the purpose of this feature?

Of course, originally, I should have typed:

echo "bob">other\ name
share|improve this question
up vote 12 down vote accepted

This is how bash redirection works.

Writing this:

echo "bob">other name

is equivalent to this:

echo "bob" name >other

redirection can appear anywhere on the line, the chevron (>) only applies to "other".

This allows people flexibility of how they wish to structure their commands. If it looks more clear doing something like this:

>file.txt echo "one" "two" "three"

then that is up to the person writing the script or command.

share|improve this answer

You must log in to answer this question.

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