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.
More Things I Wish I’d Known About Bash
11–20 of 50 posts
Re: More Things I Wish I’d Known About Bash
#12Sigh. Hit ‘up’, ‘left’ until at the ‘p’ and type ‘e’ and return. One could also use , and to achieve the same result much quicker.
Re: More Things I Wish I’d Known About Bash
#13- 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
#14Sigh. 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…
Re: More Things I Wish I’d Known About Bash
#15Just 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…
Re: More Things I Wish I’d Known About Bash
#16Re: More Things I Wish I’d Known About Bash
#17 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
#18UP CTRL-A RIGHT RIGHT e
Which needs less thinking and 6 keystrokes instead of 8.
Re: More Things I Wish I’d Known About Bash
#19Portuguese 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…
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.