Things I Wish I'd Known About Bash
zwischenzugs.com
Things I Wish I'd Known About Bash
1–10 of 272 posts
Re: Things I Wish I'd Known About Bash
#2- use the unofficial strict mode: http://redsymbol.net/articles/unofficial-bash-strict-mode/
- use parameter substitutions like ${foo#prefix}, ${foo%suffix} instead of invoking sed/awk
- process substitution instead of named pipes: ()
- know the difference between an inline group {} and a subshell ()
- use printf "%q" when passing variables to another shell (e.g. assembling a command locally and executing it via SSH)
Re: Things I Wish I'd Known About Bash
#3This is still wrong if the command can output spaces or meta-characters. You should quote the left operand, and then you don't need to prepend x:
if [ "$(grep not_there /dev/null)" = '' ]
Re: Things I Wish I'd Known About Bash
#4Re: Things I Wish I'd Known About Bash
#5Re: Things I Wish I'd Known About Bash
#6I suggest reading this instead: http://www.grymoire.com/Unix/Sh.html
Granted, it's about the Bourne shell, but since Bash, Korn, and every standard UNIX shell is supposed to be compatible with it, it's well worth learning.
And IMO, if you need more than what the Bourne shell provides, you should be using a proper programming language like Python instead.
Re: Things I Wish I'd Known About Bash
#7Re: Things I Wish I'd Known About Bash
#8 rename -n 's/(.*)/new$1$2/' *
There's a chance this won't work on your system.There are two incompatible versions of rename in the wild:
1) Perl one: https://metacpan.org/pod/distribution/File-Rename/rename.PL
2) from util linux: http://man7.org/linux/man-pages/man1/rename.1.html
Debian (and dertivaties) ship the former; other Linux distros likely the latter.
Re: Things I Wish I'd Known About Bash
#9#0: If you're writing scripts that are destined for other users, use POSIX sh instead.