5 ms·
Linked article is actually a really horrible intro to bash -- at best, it is an OK intro to pre-POSIX bourne shell scripting. Specifically: * test and [ ] are
by nescafe 15y ago
Linked article is actually a really horrible intro to bash -- at best, it is an OK intro to pre-POSIX bourne shell scripting.
Specifically:
* test and [ ] are fraught with parameter expansion peril. Use [[ ]] instead.
* The author uses single quotes around strings that are demonstrating parameter expansion. Single quotes inhibit parameter expansion, so every one of those examples is wrong.
* select is a better tool than read; case for most of his case-relasted demos.
* Backticks ( ` ` ) are the devil.
At least he points people greg's wiki at the end.
- morsch 15y agoWhat's wrong with using backticks?
- babarock 15y agoThey don't nest as well as $()
- gbog 15y agoAnd backticks can easily slip in when you want to tab or escape, then you can mistake them with a single-quote. Where they are really the evilest evil is in PHP. Such a dangerous things, nearly invisible!
- ajross 15y agogrumbling guy with beard walks by, mumbles "Here's a dollar kid, get yourself a real font." And walks on... Unless your shell and editor are displaying in courier, or you use extremely small glyphs (I've seen folks doing terrible things to their font scaling on 100dpi mac screens trying to get more lines on the screen) that should not be a problem. Certainly the Vera Mono font family gets this right; a backtick is quite distinct.
- deleted 15y ago[deleted]
- acqq 15y agoWhoever made the guide is unexperienced in the tasks he writes about. Otherwise he'd know about [[ and ((. Were it an intro for non-bash shells, it would be an acceptable omission. And you're not really explaining how to write conditions if you aren't explaining this: # d=abc # [ $d -eq 25 ] -bash: [: abc: integer expression expected It also looks to me that aboutlinux.info is in fact just a for-SEO-purposes generated site. Anybody knows more?
- AlexandrB 15y agoDo you know of a better intro? I wasn't even aware of [[ ]] :(
- ez77 15y agoActually POSIX does not recognize double brackets [1]: "The KornShell-derived conditional command (double bracket [[]]) was removed from the shell command language description in an early proposal. Objections were raised that the real problem is misuse of the test command ( [), and putting it into the shell is the wrong way to fix the problem. Instead, proper documentation and a new shell reserved word ( !) are sufficient." The entire section on test is full of advice on the proper use of test(1). [1] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html http://pubs.opengroup.org/onlinepubs/9699919799/utilities/te...
- acqq 15y agoThe article writes about Bash and not about POSIX standardization of test command which omits double brackets.
- ez77 15y agoI replied to a specific comment, not to the article. In particular, nescafe said this was "an OK intro to pre-POSIX bourne shell scripting". I took this to mean that he would provide POSIX-endorsed suggestions. The double brackets, at least, are not "post-POSIX".