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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

greg.1.anderson’s picture

Status: Needs review » Needs work

From the page you quoted:

${parameter#word}
Remove Smallest Prefix Pattern. The word shall be expanded to produce a pattern. The parameter expansion shall then result in parameter, with the smallest portion of the prefix matched by the pattern deleted.

So, I do not think that ${MSYSTEM#5} is the same as ${MSYSTEM:0:5}.

$ x=1234567890
$ echo $x
1234567890
$ echo ${x:0:5}
12345
$ echo ${x#5}
1234567890
$ echo ${x#1}
234567890

Patches that replace ${MSYSTEM:0:5} with something more universally recognized would be welcome.

I did not review your ORIGDIR change.

Peter Bex’s picture

Sorry, 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.

greg.1.anderson’s picture

#2 looks to me like it would be okay with a comment, but I did not try it.

greg.1.anderson’s picture

greg.1.anderson’s picture

Status: Needs work » Closed (duplicate)