Closed lucaswerkmeister closed 7 years ago
(The motivation for this issue is that it’s possible to write polyglot scripts that run under both dgsh and bash, and hide the multipipe syntax in an if is_dgsh
block. The script could then offer extra features or optimizations if running under dgsh.)
Note that when running bash --dgsh
the $BASH
way doesn't work. One way I can think is
if {{ : ; }} ; then
echo dgsh
else
echo bash
fi 2>/dev/null
Why is this issue closed? Your proposed solution is alright, but without documenting it anywhere else no one will find it…
Right! I mistakenly thought that documenting it in this issue was enough. Where would you expect to find it documented? Can you please submit a corresponding pull request?
Sure, I can create a PR later.
Looking forward!
Took me a bit longer than I’d hoped for, but I’ve submitted the PR: #96.
As far as I can tell, there’s no obvious and simple way for a shell script to determine whether it’s running under dgsh or an ordinary bash:
$SHELL
is/bin/bash
,$BASH_VERSION
and${BASH_VERSINFO[@]}
look just like those of a normal Bash, etc. The ways I currently know are:type call
ortype call_with_stdin
, two default aliases ofdgsh
.$BASH
, the full path to the shell (e. g./usr/local/bin/dgsh
). It probably containsdgsh
if it’s dgsh and probably doesn’t if it’s bash.I must admit that I didn’t notice the second way until filing this issue – I went to open it because I just knew of the first way and thougt that was too obscure. With
$BASH
available, I’m not sure if this issue is still necessary… do you think a dedicated variable like$DGSH
should be added?