dspinellis / dgsh

Shell supporting pipelines to and from multiple processes
http://www.spinellis.gr/sw/dgsh/
Other
323 stars 22 forks source link

Provide way to detect whether a script is running under dsgh? #92

Closed lucaswerkmeister closed 7 years ago

lucaswerkmeister commented 7 years ago

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:

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?

lucaswerkmeister commented 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.)

dspinellis commented 7 years ago

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
lucaswerkmeister commented 7 years ago

Why is this issue closed? Your proposed solution is alright, but without documenting it anywhere else no one will find it…

dspinellis commented 7 years ago

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?

lucaswerkmeister commented 7 years ago

Sure, I can create a PR later.

dspinellis commented 7 years ago

Looking forward!

lucaswerkmeister commented 7 years ago

Took me a bit longer than I’d hoped for, but I’ve submitted the PR: #96.