Extension .exe needed for WSL! How to write a generic script? (WSL, Cygwin, Linux, MacOS)
I use docopts
in my Shell scripts. That works nicely from Cygwin.
I just need to be sure that docopts
is present, at the top of my scripts:
command -v docopts > /dev/null 2>&1 || { echo >&2 "docopts not found"; exit 2; } ... parsed="$(docopts -h "$help" -V "$version" : "$@")" eval "$parsed"
But, in WSL, it needs the extension .exe
to find the program to launch.
Should I adapt all my scripts this way?
DOCOPTS= command -v docopts > /dev/null 2>&1 && DOCOPTS=docopts command -v docopts.exe > /dev/null 2>&1 && DOCOPTS=docopts.exe [ -z "$DOCOPTS" ] && { echo >&2 "docopts not found"; exit 2; } ... parsed="$($DOCOPTS -h "$help" -V "$version" : "$@")" eval "$parsed"
Or is there a much smarter way to do that, so that my scripts will work in any environment?
Answer
My recommendation is to install docopts
in WSL rather than attempting to use the Cygwin docopts.exe
version. That will (a) allow you to use the same config (without an .exe
extension) in both, and (b) likely be more compatible. I’ve noticed and heard of a few idiosyncrasies when attempting to use Cygwin executables inside of WSL. WSL does a great job of providing the compatibility layer between Linux and Windows EXE, but Cygwin does some “magic” that might cause issues.