- 論壇徽章:
- 7
|
看到許多貼子中的代碼用到了cat命令,cat命令是unix中最常用的命令之一,但是象cat file | somecommand這種用法,現(xiàn)被稱為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。因為重定向的效率要比運(yùn)行一個外部命令要高。比如:
$ cat file | tr -d 'xyz'
runs two processes, one for cat and one for tr. This is less
efficient than
同時運(yùn)行了兩個進(jìn)程 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接受文件名作為參數(shù),也可以
$ 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 |
|