What is the difference between beetwen $ echo Hello world> file and $ echo Hello> file world in bash?

$ echo Hello world > file
$ echo Hello > file world
$ echo > file Hello world
$ > file echo Hello world

They all do the same, but I don’t know why.

+4
source share
1 answer

From man bash:

   Simple Commands
       A  simple  command  is a sequence of optional variable assignments fol-
       lowed by blank-separated words and redirections, and  terminated  by  a
       control operator.  The first word specifies the command to be executed,
       and is passed as argument zero.  The  remaining  words  are  passed  as
       arguments to the invoked command.

That is, it does not indicate the order of "words and redirections." Later in the REDIRECTIONS section:

REDIRECTION
       [...]
       The [...] redirection  opera-
       tors may precede or appear anywhere within a simple command or may fol-
       low a command.  Redirections are processed in the  order  they  appear,
       from left to right.
       [...]

Thus, they can appear anywhere.

And as you yourself have observed, there is no difference between them in terms of the result. However, the difference in readability is different.

This is the most intuitive way to write it:

echo Hello world > file

Really easy to understand. >looks like an arrow, doesn't it.

, . .

+5

Source: https://habr.com/ru/post/1612841/


All Articles