Live data from Hacker News

Things I Wish I'd Known About Bash

zwischenzugs.com

51–60 of 272 posts

Re: Things I Wish I'd Known About Bash

#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 reason, this documentation is hard to find! It's not here, for example:

http://readline.kablamo.org/emacs.html

I'm a bit saddened when readline replacements don't implement C-o. For example, the Python REPLs don't have it.

Re: Things I Wish I'd Known About Bash

#54

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 might want to search with

    /   -p

Re: Things I Wish I'd Known About Bash

#55

Two important things missing: 1) This is a huge pet peeve of mine, but it kills me when my coworkers "bash" emacs and sing the praise of vim, then proceed to explain to me that ctrl-R in bash searches for the last command with a given pattern. They also often refuse to believe me that they're basically using emacs controls (because you know emacs' dirty). So, please, if you're in love with vim and use ksh or bash, le…

> they're basically using emacs controls

But not well implemented! You're supposed to be able to edit your search string, and I've never found a way.

Re: Things I Wish I'd Known About Bash

#56

#0: If you're writing scripts that are destined for other users, use POSIX sh instead.

Are you writing your scripts in sh instead of bash, perl, python, JavaScript?

I prefer sh over bash for most of my scripts, but I will sometimes use Python instead.

Re: Things I Wish I'd Known About Bash

#57
post #32

+1 for the parts that are portable to Bourne shell/ksh/zsh. -1000 for the parts that are specific to Bash. Stuff like that has been huge pain in my ass over the years. Some clever programmer uses some bash-ism and the build breaks on some ancient hardware that doesn't have bash. I realize my complaint sounds like Henry Spencer's Ten Commandments and perhaps it feels outdated but trust me, you don't want to wade into…

The article doesn't mention which are portable and which aren't.

It's a cultural thing. GNU is intended to replace Unix, so interoperability is (at best) not a priority. Same as Microsoft's “embrace, extend, extinguish”, which shows how important a good slogan is if you want your ambitions recognized.

A POSIX (or older Bourne-descended) shell can be distinguished from ‘bash --posix’ in a script with a fragment like “date&>F”, because Bash authors either didn't realize or didn't care that the sequence ‘&>’ already had meaning.

Re: Things I Wish I'd Known About Bash

#58

Earlier quoted context omitted.

Exactly: GNU bash is on most GNU/Linux systems, but: * mac OS uses an ancient version of bash * Embedded systems use busybox sh * Android uses its own version of sh * None of the BSDs come with bash, since, y'know GNU licensing EDIT: Formatting

And to make things interesting Ubuntu uses dash as sh https://wiki.ubuntu.com/DashAsBinSh

In fairness, that's just for sh; if for some reason you actually need bash you can just use `#!/usr/bin/env bash`

Re: Things I Wish I'd Known About Bash

#60

Two important things missing: 1) This is a huge pet peeve of mine, but it kills me when my coworkers "bash" emacs and sing the praise of vim, then proceed to explain to me that ctrl-R in bash searches for the last command with a given pattern. They also often refuse to believe me that they're basically using emacs controls (because you know emacs' dirty). So, please, if you're in love with vim and use ksh or bash, le…

> they're basically using emacs controls But not well implemented! You're supposed to be able to edit your search string, and I've never found a way.

Huh? Backspace works the same for me in Bash C-r as it does in Emacs C-r.
Post reply on HN