Re:Show HN: Bish – Shell scripting with a modern feel
by alphapapa on Sunday March 08, 2015 @08:08PM
(#9167990)
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.
Re:Show HN: Bish – Shell scripting with a modern feel
by yramagicman on Sunday March 08, 2015 @08:18PM
(#9168032)
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.
[1] https://github.com/yramagicman/dotfiles [2] https://github.com/yramagicman/zsh-aliases [3] https://github.com/mathiasbynens/dotfiles/blob/master/.funct...
Re:Show HN: Bish – Shell scripting with a modern feel
by alphapapa on Wednesday March 11, 2015 @11:43AM
(#9184641)
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
[1]https://github.com/mooz/percol/
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.