cake-build / resources

Contains different kind of resources such as bootstrappers and configuration files.
MIT License
54 stars 79 forks source link

build.sh file performance issue #63

Closed VladislavAntonyuk closed 3 years ago

VladislavAntonyuk commented 5 years ago

Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead if [ ! -f "$PACKAGES_CONFIG_MD5" ] || [ "$( cat "$PACKAGES_CONFIG_MD5" | sed 's/\r$//' )" != "$( $MD5_EXE "$PA...

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 seek-able input, like tail or tar. Many tools also accept optional filenames, e.g. grep -q foo file instead of cat file | grep -q foo. Example of incorrect code:

cat file | tr ' ' _ | nl
cat file | while IFS= read -r i; do echo "${i%?}"; done

Example of correct code:

< file tr ' ' _ | nl  
while IFS= read -r i; do echo "${i%?}"; done < file
devlead commented 5 years ago

The build.sh mentioned is located at https://github.com/cake-build/resources/blob/3c215479b28fe23663e051764950653fd458a1cd/build.sh#L70

Which is where you can send PR against.