Live data from Hacker News

Things I Wish I'd Known About Bash

zwischenzugs.com

81–90 of 272 posts

Re: Things I Wish I'd Known About Bash

#81
post #30

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?

Yes, you would write non-trivial install scripts in ruby.

https://en.m.wikipedia.org/wiki/Chef_(software)

Re: Things I Wish I'd Known About Bash

#82

Earlier 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.

>So you use python instead of sh

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

#83

Earlier 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

#84

Earlier 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.

If foo has a Texinfo manual (GNU tools like bash usually do) then you can try `info foo` and search the index with i or I for -p. Texinfo manuals also have hyperlinks you can press enter on.

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

#85
post #52

Using 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…

I've overridden ctrl-r in my local Bash to search with fzf[0] and I'm using my history so much more now.

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

#86
post #62
post #30

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.

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…

As someone who has to occasionally modify 100+ line bash scripts written by Coworkers from Christmas Past which matched your spec in terms of what they had to do, please please just use Python (or similar).

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

#87
post #72
post #59

This 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…

Id' imagine they dont include it because the descriptions are very intertwined and complicated. I don't even know what they all mean but I usually just google this mess.

Re: Things I Wish I'd Known About Bash

#90

Earlier 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.

You can also do keyword searches across all man pages like:

    man -k 
Post reply on HN