On Tuesday, September 01, 2015 21:55:28 albatroz via Digitalmars-d-learn wrote: > Hi, since the upgrade to the latest version the function > executeShell (also the other functions), is not working has it > used to be, older versions of the compiler did not require any > change or setting the SHELL. > > How to change the SHELL, that is used by executeShell? userShell > will always return /bin/sh. > > I've tested by setting the SHELL to /bin/bash using the > environment function. If I execute echo $SHELL inside the > executeShell it will show /bin/bash has expected. > > My issue is that the command I'm executing inside executeShell is > throwing and error and showing that the execution is done by > /bin/sh. > > My code: > executeShell("diff -u <(echo "~data1~") <(echo "~data2~")"); > > Output: > /bin/sh: 1: Syntax error: "(" unexpected > > This is caused by a limitation from /bin/sh that cannot perform > process substitution. > > Can this commit be the reason? > https://github.com/D-Programming-Language/phobos/commit/a524a3571b18e440c4dd751fcf4e2d00b834fb22
Well, based on the information in the corresponding bug report and comments in the PR, it sounds like it's generally considered best practice to always use /bin/sh, because it's consistent, whereas who knows what SHELL is set to. Sure, it's common on Linux systems for it to be bash, but there are plenty of Linux systems where it isn't, and other POSIX systems like FreeBSD typically have sh as the default, and many users commonly use shells like csh or tcsh rather than bash. And of course, the folks who want a particularly fancy shell use zsh. So, while bash is probably the most commonly used shell, it's still fairly common for folks to use other shells, and if you want consistent behavior, you need sh. That being said, userShell clearly now is inconsistent with its documentation, and it probably would have been better to just make the other std.process functions use /bin/sh than to change userShell, since SHELL really is the user's shell. Now, if you want to specifically force the use of bash, I think that you're going to have to use execute or spawnProcess and use /bin/bash as the command. That's definitely more annoying, but if you look at the implementation for spawnShell, it sets arguments to pass to spawnProcess to spawn the shell. executeShell and execute seem more complicated to figure out how they work, but presumably it's possible to pass a similar command to execute in order to simulate executeShell with /bin/bash. - Jonathan M Davis