3 ms·
As opposed to improper bash? Get off your high horse. There is very much a bad way of doing bash. When I first started doing bash scripts, most of them looked
by AdmiralAsshat 11y ago
As opposed to improper bash? Get off your high horse.
There is very much a bad way of doing bash. When I first started doing bash scripts, most of them looked like this:
cat file | grep string
cat file | wc
cat file | while read line
Multiple problems there. Then there was my initial attempts at finding files in a directory:
for i in `ls *`
This is when I learned about globbing.
There is enough variance in how things can be done in Bash with varying degrees of effectiveness that Google even has a Shell Style Guide:
https://google.github.io/styleguide/shell.xml https://google.github.io/styleguide/shell.xml
- joepvd 11y agoThanks for the link to the Google Bash Style Guide. A good read.
- nomadictribe 11y agohttps://google.github.io/styleguide/shell.xml https://google.github.io/styleguide/shell.xml my fx doesn't render the site properly it's just one huge blob of continuous text. impossible to read. why would they do it as an *.xml?
- coldpie 11y agoIt's an XSL document. I guess your browser settings block using XSL stylesheets to render the XSL document correctly.
- narrowrail 11y agoYou could try this version: https://github.com/google/styleguide/blob/gh-pages/shell.xml https://github.com/google/styleguide/blob/gh-pages/shell.xml
- m0nty 11y agoWe all get tricked by the "useless use of cat" thing occasionally :)
- drivers99 11y agoI'm not so sure it is so useless. Consider when you want to "grep something access.log". Then you want to look at yesterday's so it's "grep something access.log.1". Then you want to look at the log before that, but it's compressed. "gunzip -c access.log.2.gz | grep something". (Ignore zgrep for the moment. Let's say I want to use grep's -A and -B options to show context of the lines that it finds.) To switch between the compressed and uncompressed files, you have to move the filename to a completely different part of the command, which requires more re-typing. You would have been better off starting with so-called "useless" cat. Separate out the concern of "putting a stream into the pipe" from "doing something with the stream". gunzip -c is just one command that might produce output.