Jes*_*tro 5 bash shell console command
$ echo Hello world > file
$ echo Hello > file world
$ echo > file Hello world
$ > file echo Hello world
Run Code Online (Sandbox Code Playgroud)
他们都做同样的事情,但我不知道为什么.
来自man bash
:
Run Code Online (Sandbox Code Playgroud)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.
也就是说,它没有指定"单词和重定向"的顺序.稍后在REDIRECTIONS部分:
Run Code Online (Sandbox Code Playgroud)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. [...]
所以它们可以出现在任
正如你自己也观察到的那样,它们在结果方面没有区别.但是在可读性方面存在差异.
这是最直观的编写方式:
echo Hello world > file
Run Code Online (Sandbox Code Playgroud)
真的很容易理解.在>
看起来像一个箭头,不是吗.
其他不是那么直观,不太可读.我建议坚持第一种写作风格.
归档时间: |
|
查看次数: |
399 次 |
最近记录: |