Updated SC2002 (markdown)

koalaman
2017-06-05 16:26:02 -07:00
parent 17f256db3d
commit f30491f6fa

@@ -3,15 +3,15 @@
### Problematic code:
```sh
cat file | tr ' ' _ | grep a_
cat file | ( while read i; do echo "${i%?}"; done )
cat file | tr ' ' _ | nl
cat file | while IFS= read -r i; do echo "${i%?}"; done
```
### Correct code:
```sh
< file tr ' ' _ | grep a_ # **simple commands only, won't work with compounds
( while read i; do echo "${i%?}"; done ) < file # postfix works for everything
< file tr ' ' _ | nl
while IFS= read -r i; do echo "${i%?}"; done < file
```
### Rationale:
@@ -24,4 +24,4 @@ Many tools also accept optional filenames, e.g. `grep -q foo file` instead of `c
### Exceptions
None.
Pointing out UUOC is a long standing shell programming tradition, and removing them from a short-lived pipeline in a loop can speed it up by 2x. However, it's not necessarily a good use of time in practice, and rarely affects correctness. [[Ignore]] as you see fit.