- 论坛徽章:
- 7
|
看到许多贴子中的代码用到了cat命令,cat命令是unix中最常用的命令之一,但是象cat file | somecommand这种用法,现被称为UUOC,是一种效率低的用法。
摘自Shell FAQ:
UUOC
This is short for "Useless use of cat". It's used to point out
that some example script has used cat when it could have used
redirection instead. It's more efficient to redirect input than
it is to spawn a process to run cat. For example
UUOC是"Useless use of cat"的缩写。如果脚本中使用cat命令的代码可以用"重定向"代替,你就可以称其为UUOC。因为重定向的效率要比运行一个外部命令要高。比如:
$ cat file | tr -d 'xyz'
runs two processes, one for cat and one for tr. This is less
efficient than
同时运行了两个进程 cat 和 tr,这种用法的效率比下面这句要低
$ tr -d 'xyz' < file
In general, "cat file | somecommand" can be more efficiently
replaced by "somecommand < file"
or (especially for multi-file input)
通常,"cat file | somecommand"可以替换成"somecommand < file"
如果somecommand接受文件名作为参数,也可以
$ somecommand file [file ...]
but check the man page for "somecommand" to find out if it will
accept this syntax.
For more details about this, as well as other things like it, see
http://rhols66.adsl.netsonic.fi/era/unix/award.html |
|