Better Bash Scripting in 15 Minutes
The tips and tricks below originally appeared as one of Google's "T esting on the Toilet" (TOTT) episodes.
I start every bash script with the following prolog:
#!/bin/bash
set -o nounset
set -o errexit
Use functions
- Favor $() over backticks (`)
- Favor [[]] (double brackets) over []
- Avoiding Temporary Files with <()
linux - How to reverse-i-search back and forth? - Super User
I use reverse-i-search often, and that's cool. Sometime though when pressing Ctrl+r multiple times, I pass the command I am actually looking for. Because Ctrl+r searches backward in history, from n...
The one-sentence answer: Run stty -ixon in your terminal, and then use Ctrl+S to change the search direction from backward to forward.
Shell Script Best Practices — The Sharat's
This article is about a few quick thumb rules I use when writing shell scripts that I’ve come to appreciate over the years. Very opinionated....
Ten Things I Wish I’d Known About bash – zwischenzugs
diff <(grep somestring file1) <(grep somestring file2)
:h
I use this one a lot too. If you put it after a filename, it will change that filename to remove everything up to the folder. Like this:
grep isthere /long/path/to/some/file/or/other.txt
cd !$:h
Seven Surprising Bash Variables
1) PROMPT_COMMAND
2) HISTTIMEFORMAT
3) CDPATH
See comment:
https://unix.stackexchange.com/questions/456866/how-can-i-suppress-printing-the-full-path-to-subdirectories-when-using-cdpath/456867#456867
4) SHLVL
5) LINENO
6) REPLY
7) TMOUT