Live data from Hacker News

More Things I Wish I’d Known About Bash

zwischenzugs.com

11–20 of 50 posts

Re: More Things I Wish I’d Known About Bash

#13
Just another plug for Zsh: it has all of these features and then some.

- Safe-by-default parameter expansion: no word splitting unless you ask for it, even if you don't quote the expansion.

- Ability to use histoy expansions (like !!:gs/foo/bar) on parameter expansions, meaning "${foo:A:h}" is equivalent to "$(dirname $(realpath $foo))"

- Much better array support, including both integer-indexed and associative arrays

- A built-in CLI option parser that's pretty robust ("zparseopts")

- Lazy-loaded functions

- Floating-point arithmetic

Re: More Things I Wish I’d Known About Bash

#14
post #5

Sigh. Hit ‘up’, ‘left’ until at the ‘p’ and type ‘e’ and return. One could also use , and to achieve the same result much quicker.

Yup. The moment you need editing capabilities more sophisticated than those three keys, though, I recommend switching to vi input mode (set -o vi) if you are familiar with vim keybindings. Although tapping Esc is not as quick as Ctrl (or, my chosen alternative, Ctrl-[), you have an entire library of editing commands already at your beck and call. I find that using 'f' or 'F' and '.' more quickly triangulates the prob…

IMO you might as well run "fc" (if you have vim set as your editor) in that case, rather than changing mode.

Re: More Things I Wish I’d Known About Bash

#15

Just another plug for Zsh: it has all of these features and then some. - Safe-by-default parameter expansion: no word splitting unless you ask for it, even if you don't quote the expansion. - Ability to use histoy expansions (like !!:gs/foo/bar) on parameter expansions, meaning "${foo:A:h}" is equivalent to "$(dirname $(realpath $foo))" - Much better array support, including both integer-indexed and associative array…

People keep mentioning zsh to me in response to this article - I think I'll have to go and read up on it more.

Re: More Things I Wish I’d Known About Bash

#16

I imagine most uses of random in Bash don't need to be that robust, but it might be worth mentioning that ${RANDOM}${RANDOM} has a lot of bias as a random number generator.

Fair point - have updated accordingly.

If you want 30 rather than 15 bits of randomness:

    echo $(((RANDOM 

Re: More Things I Wish I’d Known About Bash

#17
As I mentioned in my comment on the article, setting $TMOUT if you want a timeout on a 'read' command is unnecessary and unclear. Just use "read -t":

    read -t 5 foo || foo='No reply'
Setting $TMOUT affects all following 'read' commands. Also, setting $TMOUT in an interactive shell sets a timeout for a response to the primary prompt, terminating the shell if the user doesn't respond in time.

Re: More Things I Wish I’d Known About Bash

#19

Portuguese speakers have counted for a long time with this gem, simply the best Bash doc/cheat sheet I've ever seen on the web. This is probably my oldest bookmark still relevant after 15 years. It's in portuguese and I'm not sure if there's an official translation, yet it's easy enough to decipher if you know bash, and Google Translate will do a pretty decent job. I gift you "Aurelio's Swiss Army Knife of the Bash S…

Ah, curious. Despite being a native Portuguese speaker, ever since I learned English well enough (which was before I started using Linux), I always search for stuff in English, so I never came across that guide.

That said, that guide doesn't seem to have the tricks from the top article, at least 1-4.

Re: More Things I Wish I’d Known About Bash

#20

"Sigh. Hit ‘up’, ‘left’ until at the ‘p’ and type ‘e’ and return.". My solution for this one would be : UP CTRL-A RIGHT RIGHT e Which needs less thinking and 6 keystrokes instead of 8.

Even better: https://github.com/nvbn/thefuck
Post reply on HN