LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Question about why a command does this (https://www.linuxquestions.org/questions/linux-newbie-8/question-about-why-a-command-does-this-828191/)

SentralOrigin 08-24-2010 09:09 AM

Question about why a command does this
 
Code:

$ echo 2 * 3 > 5 is a valid inequality.
This will create a file in the current directory named '5' with the number '2' in it, the names of all the files in the current directory, followed by the number '3' and 'is a valid inequality.'

What I do not understand is why 'is a valid inequality' gets written to this file. I thought it would write '2', all the file names in the current directory, then '3' into the file called '5'. Why does the 'is a valid inequality.' get written to the file also?

GrapefruiTgirl 08-24-2010 09:13 AM

Hmm.. What shell are you using, and what version? Not sure if it matters, but thought I'd ask, since for me, the command works as you would expect it to, I think:
Code:

root@reactor: echo 2 * 3 > 5
root@reactor: cat 5
2 crap crappo.tex 3
root@reactor:

:scratch:

SentralOrigin 08-24-2010 09:19 AM

bash 3.2.something I think (it says bash 3.2 when I do $SHELL but I remember seeing a bunch of other numbers somewhere else)

Code:

$ echo 2 * 3 > 5 is a valid inequality.
$
$ cat 5
2 somefolder somefiles 3 is a valid inequality.
$


grail 08-24-2010 09:38 AM

yes i get the same results as you OP. Here is something else to prove the point:
Code:

echo > 7 one two * three
This will create the file '7' with strings 'one', 'two', contents of current directory and 'three' inside it.
Echo is treating all fields presented to it individually, as there are no quotes. The moment it finds the redirection it knows that it should send all data
it finds to that location. As it then finds more strings on the line it then processes those and acts accordingly.


All times are GMT -5. The time now is 05:02 PM.