From cc3409d6ca3e996425d6a0808590e521a9933d6f Mon Sep 17 00:00:00 2001 From: koalaman Date: Sat, 8 Feb 2014 14:42:15 -0800 Subject: [PATCH] Created SC2002 (markdown) --- SC2002.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 SC2002.md diff --git a/SC2002.md b/SC2002.md new file mode 100644 index 0000000..e893980 --- /dev/null +++ b/SC2002.md @@ -0,0 +1,21 @@ +# Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead. + +### Problematic code: + + cat file | tr ' ' _ + +### Correct code: + + tr ' ' _ < file + +### Rationale: + +`cat` is a tool for con"cat"enating files. Reading a single file as input to a program is considered a [Useless Use Of Cat (UUOC)](http://en.wikipedia.org/wiki/Cat_(Unix)#Useless_use_of_cat). + +It's more efficient and less roundabout to simply use redirection. This is especially true for programs that can benefit from seekable input, like `tail`. + +Many tools also accept optional filenames, e.g. `grep -q foo file` instead of `cat file | grep -q foo`. + +### Contraindications + +None. \ No newline at end of file