I'm with you. I have written a mountain of Bash scripts to solve various one-off problems, and I'm fucked if I can ever remember the nuances from one time to the next -- when to use [], when [[]], when () or (()), when the dollar sign precedes (), etc. Every single time I have to do anything in Bash I have to re-learn Bash. I suppose I keep using it because, even with having to re-learn every single element of Bash coding every time, it's still faster for doing a bunch of filesystem stuff for me. But god, I hate it. I can't think of a computer technology I hate more. I hate it more than R, and I really hate R too, for some of the same reasons.
I keep intending to learn Perl really well, which I think could absorb much of Bash, and also Awk and Sed, and then there would be only one thing I needed to know for this kind of work, and I might use it enough to remember the various weird syntactic bits from one month to the next. But I never quite get over the hump.
Always use double-brackets [[ ]] if you're writing Bash (not sh) scripts. They are better.
Double-parentheses (( )) are only for arithmetic, e.g. "((count++))" or "echo $((1+1))"
The dollar sign precedes parentheses--i.e. $()--when you're substituting the output of a command, e.g. "echo Today is $(date)". It's easy to remember, because it's just like using the dollar sign for substituting the value of a variable, i.e. "date=$(date); echo $date".
You might want to look into the fish shell. Its scripting is much less idiosyncratic. You don't have to quote any variables, arrays, or command substitutions. e.g.:
set foods apple banana 'cucumber casserole'
for f in $foods
echo $f
end
prints:
apple
banana
cucumber casserole
...not:
apple
banana
cucumber
casserole
...as would be the case if you forgot to quote "$foods" and "$f" in Bash.
My dotfiles[1,2] are full of various functions to do stuff. Half of them I jacked from other people[3] when I was using Bash and ported to ZSH when I discovered Oh-my-zsh. However, a few are my own. The ones that I did write are often one-liners that take an argument and pass it to a series of commands that I'd rather not type. For example history | grep -i command, ls -lah | grep dir, or my favorite, cd dir; ls. If I have to do any logic, aside from determining what OS I'm on, I look to python.
You seem like the kind of person who'd appreciate Percol[1]. It's fantastic for shell history. I have it bound to Ctrl+R:
history | percol --prompt-bottom --result-bottom-up
I'm using fish, so the whole thing looks like this:
function _percol_key_bindings
function __percol_ctrl_r
set tempfile (mktemp)
history | percol --prompt-bottom --result-bottom-up >$tempfile
and commandline (cat $tempfile)
commandline -f repaint
rm -f $tempfile
end
# Bind Ctrl+R to percol history function for now
bind \cr '__percol_ctrl_r'
end
I keep intending to learn Perl really well, which I think could absorb much of Bash, and also Awk and Sed, and then there would be only one thing I needed to know for this kind of work, and I might use it enough to remember the various weird syntactic bits from one month to the next. But I never quite get over the hump.