secluded secluded - 7 months ago 33
Bash Question

bash "echo" including ">" in the middle creating file - please explain

When I write:

echo 2*3>5 is a valid inequality

in my bash terminal, a new file named
is created in my directory which contains:

2*3 is a valid inequality

I want to know what exactly is going on here and why am I getting this output?

I believe it's obvious that I'm new to Linux!


bash does the oputput redirection first i.e. > is done first and a file named 5 is created (or truncated if exists) and the resultant file descriptor remains open for the runtime of the echo command.

Then the remaining portion i.e. 2*3 is a valid inequality runs as the argument to echo and standard output is saved in the file 5 eventually.

To get the whole string as STDOUT, use single or double quotes:

echo '2*3>5 is a valid inequality'