I wrote a book on Bash too. The most important thing for anyone to know about Bash is that it's intended as a command language, not a general purpose scripting language. If it's longer than 10 lines, or if it uses two or more variables, you should probably have written it in something other than Bash.
Would you consider non-trivial install scripts as an exception to this general rule? I mean, you wouldn't write some install script in ruby or python, right?
Things I Wish I'd Known About Bash
81–90 of 272 posts
Re: Things I Wish I'd Known About Bash
#82Earlier quoted context omitted.
I prefer sh over bash for most of my scripts, but I will sometimes use Python instead.
So you use python instead of sh, but you argue that we should use sh instead of bash, perl, or python. I'm not convinced. IMHO, we should use proper tool for the job instead of making artificial limitations. Bash is proper tool in lot of cases, unless old proprietary OS or very limited embedded OS are targeted.
That's not what I said
>we should use proper tool for the job
This is the implication of what I said.
I do not think that bash is the proper tool in most cases.
Re: Things I Wish I'd Known About Bash
#83Earlier quoted context omitted.
Which is why the parent advised to treat the man page like a reference document, by searching in it. Some man pages are just badly written and are indigestible even when searching for a specific thing, but in general, that approach works quite often.
Is there some trick to searching man pages that I don’t know? Because my usual experience is: type man foo type /-p type n n n n n n n n n as there are a bunch of matches like “...does bar when combined with -p...” A presentation of man pages that used hypertext would make me a lot happier.
man man
man less
Not a joke. Learn the simple tools that help you daily.Re: Things I Wish I'd Known About Bash
#84Earlier quoted context omitted.
Which is why the parent advised to treat the man page like a reference document, by searching in it. Some man pages are just badly written and are indigestible even when searching for a specific thing, but in general, that approach works quite often.
Is there some trick to searching man pages that I don’t know? Because my usual experience is: type man foo type /-p type n n n n n n n n n as there are a bunch of matches like “...does bar when combined with -p...” A presentation of man pages that used hypertext would make me a lot happier.
info is a greatly underused system and I'd recommend any *nix users to spend some time learning how to navigate it.
Re: Things I Wish I'd Known About Bash
#85Using readline is a great thing to know about too. My favourite little-known readline command is operate-and-get-next: https://www.gnu.org/software/bash/manual/html_node/Miscellan... You can use it to search back in history with C-r and then execute that command with C-o and keep pressing C-o to execute the commands that followed that one in history. Very helpful for executing a whole block of history. For some reaso…
Didn't know about ctrl-o though, it sounds great! I hope that my ctrl-r override doesn't somehow break it.
[0]: https://github.com/junegunn/fzf
E: Fixed link.
Re: Things I Wish I'd Known About Bash
#86I wrote a book on Bash too. The most important thing for anyone to know about Bash is that it's intended as a command language, not a general purpose scripting language. If it's longer than 10 lines, or if it uses two or more variables, you should probably have written it in something other than Bash.
I disagree. Here's how I decide: Do I need to manipulate rich data structures like hash-maps or nested lists? That sort of thing tends to stretch the capabilities of Bash to its limits and I tend to set the bar fairly low here. Is the program oriented around commands? If I'm gluing executable scripts and binaries, using bash is often superior to a scripting language. Argument passing is more natural and convenient an…
Yes, you will have a few extra lines but it will be vastly more readable and maintainable.
And yes, I know I will get the standard the person who wrote the script did a bad job but at some point it should be okay to blame the tools instead of the workman if workmen disproportionately create worse results with a set of tools.
Re: Things I Wish I'd Known About Bash
#87This is the most helpful bash diagram ever... why didn't I search for this before! https://zwischenzugs.files.wordpress.com/2018/01/shell-start...
As given in the article, it's also the most annoying bash diagram ever...it needs an explanation of what the 7 different colors of arrows mean. All that was given is: > It shows which scripts bash decides to run from the top, based on decisions made about the context bash is running in (which decides the colour to follow). > So if you are in a local (non-remote), non-login, interactive shell (eg when you run bash its…
Re: Things I Wish I'd Known About Bash
#88Re: Things I Wish I'd Known About Bash
#89Press ESC then full stop instead. Less key presses.
Re: Things I Wish I'd Known About Bash
#90Earlier quoted context omitted.
Which is why the parent advised to treat the man page like a reference document, by searching in it. Some man pages are just badly written and are indigestible even when searching for a specific thing, but in general, that approach works quite often.
Is there some trick to searching man pages that I don’t know? Because my usual experience is: type man foo type /-p type n n n n n n n n n as there are a bunch of matches like “...does bar when combined with -p...” A presentation of man pages that used hypertext would make me a lot happier.
man -k