Updated SC2002 (markdown)

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

@@ -3,15 +3,15 @@
### Problematic code: ### Problematic code:
```sh ```sh
cat file | tr ' ' _ | grep a_ cat file | tr ' ' _ | nl
cat file | ( while read i; do echo "${i%?}"; done ) cat file | while IFS= read -r i; do echo "${i%?}"; done
``` ```
### Correct code: ### Correct code:
```sh ```sh
< file tr ' ' _ | grep a_ # **simple commands only, won't work with compounds < file tr ' ' _ | nl
( while read i; do echo "${i%?}"; done ) < file # postfix works for everything while IFS= read -r i; do echo "${i%?}"; done < file
``` ```
### Rationale: ### Rationale:
@@ -24,4 +24,4 @@ Many tools also accept optional filenames, e.g. `grep -q foo file` instead of `c
### Exceptions ### 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.