0

my nodejs script can't work well at msys2 shell

something worng make $basedir always become empty

than case this bug Error: Cannot find module 'C:\msys64\node_modules\gulp\bin\gulp.js'

how can i fix this?


msys2-bug-test

#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")

echo \$0 = $0

echo
echo \$\(dirname \"\$\(echo \"\$0\" \| sed -e \'s,\\,/,g\'\)\"\)
echo

echo \"$basedir\" should eq $(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
echo $(echo "$0" | sed -e 's,\\,/,g')

will output

$ msys2-bug-test
$0 = /c/Users/USER/AppData/Roaming/npm/msys2-bug-test

$(dirname "$(echo "$0" | sed -e 's,\,/,g')")

"" should eq .
/c/Users/USER/AppData/Roaming/npm/msys2-bug-test
bluelovers
  • 1,035
  • 2
  • 10
  • 22

1 Answers1

0

Replace:

basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")

by:

basedir=$(dirname $(echo "$0" | sed -e 's,\\,/,g'))

And:

echo \"$basedir\" should eq $(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
echo $(echo "$0" | sed -e 's,\\,/,g')

by:

echo \"$basedir\" should eq $(dirname $(echo "$0" | sed -e 's,\\,/,g'))
echo $(echo "$0" | sed -e 's,\\,/,g')
Renaud Pacalet
  • 25,260
  • 3
  • 34
  • 51