What fun!
* On 07 Apr 2016, Cameron Simpson wrote:
>
> Ah. I like zsh for my interactive shell. But we always leave root's shell
> alone. However, I am a _very_ strong advocate for writing scripts for
> /bin/sh, and avoiding bashisms for exactly your reasons above. Am I alone in
> wincing everytime I hear the term "bash scripting" these days?
No, you're not. :) I haven't brought myself to use zsh yet, because
I do a lot of /bin/sh snippet teseting in my interactive shell and I
like it to interpret bourne code correctly. Bash does, but zsh does
not -- even with all the compatibility options set. There are certain
bourne sequences that zsh does the wrong thing with, and that affects my
scripting.
> > Though, the
> > switch in many Linux distros to dash as the system shell has somewhat
> > thwarted me--dash isn't (IMO) usable as an interactive shell, has some
> > issues as a scripting shell, and has slightly different semantics (BSD
> > vs. SysV echo, for instance) than bash on some oft-used builtins,
> > etc.. I find this extremely annoying. I get why they did it, but I
> > think it would have been a much better idea to produce a
> > bash-workalike shell for the subset of features they wanted to
> > support. Or patch dash to behave the same where its supported
> > features differ. Anyway, I digress.
>
> Oh, please digress!
I tend to like dash, although my experience of it is limited. I didn't
like ash but dash seems pretty solid so far. And its code is quite
readable. This is excellent. Bash is a morass.
> but printf for parameterised output:
>
> printf '%s\n' "$arbitrary_value"
I've started leaning on printf for newline-less printing lately -- it's
just easier. But you must be careful to use 'printf %s "$foo"' instead
of just 'printf $foo', since otherwise a % in input can thwart.
> and I have my own script "necho" for "echo with no newline" for the
> appropriat platform (or I make a shell function necho() calling printf for
> the same purpose, depending on context). Then one can go:
Let's see if I can get this right from memory:
case "`echo -n`" in)
-n) necho () { echo "$@""\c"; };;
*) necho () { echo -n "$@"; };;
esac
Speaking of which, it's taken me until the last year to use $(command)
consistently instead of `command`, and I'm not sure anymore why I was
a stickler. I assume some older shell didn't support $() but I can't
recall which.
--
David Champion • [email protected]