
SSH Config Trick - kiyanwang
http://dhruvasagar.com/2017/10/07/ssh-config-trick
======
stephenr
The shown shell script targets /bin/sh but uses several bashisms.

Also, the whole concept is largely irrelevant now as ssh_config _has_ an
Include directive: [https://manpages.debian.org/stretch/openssh-
client/ssh_confi...](https://manpages.debian.org/stretch/openssh-
client/ssh_config.5.en.html)

~~~
dhruvasagar
You are right! I've updated my article since then. At the time I was solving
this problem however this wasn't supported, I just happened to blog about it
now. Good to know though!

~~~
stephenr
Sure, I understand this was definitely a problem for a long time, it just
seemed odd to post it now (I initially thought maybe it was a new submission
of an old blog post).

FYI Your shell script is still not really valid. You should either fix the
bash-isms (best option) or target bash specifically in the shebang line.

ShellCheck ([http://www.shellcheck.net](http://www.shellcheck.net)) should
help with making it sh (posix shell) compatible.

Edit: probably more friendly.

~~~
dhruvasagar
alright will have a closer look, I use zsh so it can be harder to spot such
problems.

~~~
stephenr
So, this isn't really related to which interactive shell you use. The script
is executed in the shell named by the shebang (#!/bin/sh) line.

/bin/sh though, is a bit of a "special" case - back in the day, it would have
been the Bourne Shell (as distinct from Bash, which is the Bourne Again
Shell).

These days, it depends on your platform - macOS uses Bash to provide /bin/sh,
Debian/etc use Dash, and I believe the BSD's use Almquist (ash).

Dash and Ash (which Dash is a 'descendant' of) are pretty close to POSIX
compliant, but 'Bash as /bin/sh', while being 'more strict', doesn't drop
support for all Bash-isms, so your script probably works fine on macOS but
will fail miserably on a recent Linux or BSD.

Edit: FYI, if anyone wants to properly test portable (i.e. POSIX /bin/sh
compatible) shell scripts on macOS, Dash is pretty simple to install from
source. I'd still suggest using VM's to test in a variety of shells (Ash,
Dash, Posh would give pretty decent coverage) but for quick tests, native Dash
will be more representative than Bash.

