Currently the shebang line reads "#!/usr/bin/env sh". This is wrong in two ways: the first is that the shell script really isn't POSIX compatible in the substitution "x${MSYSTEM:0:5}"
(that's a bashism, apparently), the second is that POSIX mandates that the shell is installed at /bin/sh
. Some other program called "sh" might be in the user's $PATH
; it makes more sense to explicitly run /bin/sh
and fix the script to be compatible with other shells.
The fix is simply to change "x${MSYSTEM:0:5}"
to "x${MSYSTEM#5}"
, which has the same meaning but is POSIX-compatible (see the spec)
I've also noticed a small problem with the default shell under NetBSD ("ash"); it doesn't appear to completely honor the spec for the "cd" command. This causes the "cd $ORIGDIR"
trick to fail because it resolves symlinks in that directory (then Drush can't find the site and Drupal directory correctly anymore). However, if I simply change this to also export ORIGDIR
, and read that instead of the PWD
variable which is implicitly set by the shell, everything works fine. I suspect that this change might also help in doing the right thing under Windows, where PWD apparently isn't set at all. The bat-file could simply export the current directory, I think.
Comment | File | Size | Author |
---|---|---|---|
0001-Fix-POSIX-compatibility-in-shell-replacement-pattern.patch | 1.95 KB | Peter Bex |
Comments
Comment #1
greg.1.anderson CreditAttribution: greg.1.anderson commentedFrom the page you quoted:
So, I do not think that ${MSYSTEM#5} is the same as ${MSYSTEM:0:5}.
Patches that replace ${MSYSTEM:0:5} with something more universally recognized would be welcome.
I did not review your ORIGDIR change.
Comment #2
Peter Bex CreditAttribution: Peter Bex commentedSorry, you're totally right. How about changing it to
[ "x${MSYSTEM}" != "x${MSYSTEM#MINGW}" ]
? If they're identical, the prefix pattern wasn't removed; if they differ, MINGW was a prefix pattern.Comment #3
greg.1.anderson CreditAttribution: greg.1.anderson commented#2 looks to me like it would be okay with a comment, but I did not try it.
Comment #4
greg.1.anderson CreditAttribution: greg.1.anderson commentedSee also #820870: Make drush script more compatible with non-POSIX shells [ORIGDIR=$' unexpected].
Comment #5
greg.1.anderson CreditAttribution: greg.1.anderson commentedPatch merged in with #820870: Make drush script more compatible with non-POSIX shells [ORIGDIR=$' unexpected].