4 ms·
A guy publishing a guide for "defensive bash programming", who, in the process, provides this listing as an example for anything, is not fit for publishing said
by c0l0 11y ago
A guy publishing a guide for "defensive bash programming", who, in the process, provides this listing as an example for anything, is not fit for publishing said guide in the first place:
main() {
local files=$(ls /tmp | grep pid | grep -v daemon)
}
- brianzelip 11y agoYou might have been better off reading the text after the code example that came after the code you quoted. The text read: - Second example is much better. Finding files is the problem of temporary_files() and not of main()’s. This code is also testable, by unit testing of temporary_files(). - If you try to test the first example, you will mish mash finding temporary files with main algorithm.
- potatosareok2 11y agoThe problem isn't where it is - using "ls" to find files is never a good idea from my understanding. I think it's because of ls garbling file names but I might be mistaken there. That the author is using that to find files is reasonable enough to me to disregard the rest of the blog. edit: take that back...looked through rest of blog but don't see anything useful. I hate his idea for functions for builtins, using local is ok, please don't break up shell pipelines over N lines for simple stuff
- peeters 11y agoGoogle also mandates that you shouldn't assign to a local var at declaration, because the exit code of the function producing the value is overwritten by the exit code to `local`. https://google.github.io/styleguide/shell.xml?showone=Use_Local_Variables#Use_Local_Variables https://google.github.io/styleguide/shell.xml?showone=Use_Lo...