Bash排序重定向 [英] Bash Sorting Redirection

查看:61
本文介绍了Bash排序重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

sort file1 -o file2 sort file1>有什么区别?file2 吗?到目前为止,我做的事情与他们做的事情相去甚远,但也许我错过了一些事情.

What are the differences between sort file1 -o file2 and sort file1 > file2 ? So far from what I have done they do the same thing but perhaps I'm missing something.

推荐答案

结果相同,但对于 -o file2 ,结果文件由 sort 直接,而在另一种情况下,则由 bash 创建,并用 sort 的标准输出填充.在coreutils中的 sort.c 的第450行中定义的 xfopen 处理这两种情况( stdout -o filename )同样.

The result is the same but in the case of -o file2 the resulting file is created by sort directly while in the other case, it is created by bash and filled with the standard output of sort. The xfopen defined in line 450 of sort.c in coreutils treats both cases (stdout and -o filename) equally.

重定向 sort 的标准输出更为通用,因为可以使用 | 代替> 重定向到另一个程序,使用 -o 选项会使操作更加困难(但并非不可能)

Redirecting the standard output of sort is more generic as it could be redirected to another program with a | in place of a >, which the -o option makes more difficult to do (but not impossible)

-o 选项很方便进行原位排序,因为重定向到同一文件将导致文件被截断,因为它是在调用<之前由外壳程序创建(并被截断)的.代码>排序.

The -o option is handy for in place sorting as the redirection to the same file will lead to a truncated file because it is created (and truncated) by the shell prior to the invocation of sort.

这篇关于Bash排序重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆