cat
SH-2002662echo "// +build ${GOARCH},${GOOS}"
663echo
664go tool cgo -godefs -- "$@" _const.go >_error.out
665cat _error.out | grep -vf _error.grep | grep -vf _signal.grep666echo
667echo '// Errors'
668echo 'const ('
666echo
667echo '// Errors'
668echo 'const ('
669cat _error.out | grep -f _error.grep | sed 's/=\(.*\)/= syscall.Errno(\1)/'670echo ')'
671
672echo
672echo
673echo '// Signals'
674echo 'const ('
675cat _error.out | grep -f _signal.grep | sed 's/=\(.*\)/= syscall.Signal(\1)/'676echo ')'
677
678# Run C program to print error and syscall strings.
77
78 pushd "$dir"
79 go test -covermode=atomic -coverpkg=./... -coverprofile=coverage.out.tmp ./...
80 cat coverage.out.tmp | grep -v testsuite | grep -v tomltestgen | grep -v gotoml-test-decoder > coverage.out 81 go tool cover -func=coverage.out
82 popd
83
116
117 target_diff="${output_dir}/target.diff.txt"
118 head_diff="${output_dir}/head.diff.txt"
119 cat "${target_out}" | grep -E '^github.com/pelletier/go-toml' | tr -s "\t " | cut -f 2,3 | sort > "${target_diff}"120 cat "${head_out}" | grep -E '^github.com/pelletier/go-toml' | tr -s "\t " | cut -f 2,3 | sort > "${head_diff}"
121
122 diff --side-by-side --suppress-common-lines "${target_diff}" "${head_diff}"
Consider using cmd < file | ..
or cmd file | ..
instead.
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).
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
or tar
.
Many tools also accept optional filenames, e.g. grep -q foo file
instead of cat file | grep -q foo
.
cat file | tr ' ' _ | nl
cat file | while IFS= read -r i; do echo "${i%?}"; done
< file tr ' ' _ | nl
while IFS= read -r i; do echo "${i%?}"; done < file
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.