0

I have these:

An shell executable file:

function print() {
    echo 1
}

The package.json` file

{
  "name": "tests",
  "scripts": {
    "test": "./shell.sh"
  }
}

When I ran npm test on a linux machine, I got this error

> tests@ test /home/xxxx/test
> ./shell.sh

./shell.sh: 1: ./shell.sh: Syntax error: "(" unexpected
npm ERR! Test failed.  See above for more details.

Why so? Anybody has some insight? I am totally puzzled.

Qiang Li
  • 10,593
  • 21
  • 77
  • 148

1 Answers1

1

This doesn't really have anything to do with Node or npm, but with the shell script missing the shebang.

Try instead e.g.

#!/bin/sh
# Note the new line above

function print() {
    echo 1
}
Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
  • with this line `#!/bin/sh` or not, it shows the same error. :( This error only occurs in a linux machine, not on my mac. – Qiang Li Sep 09 '15 at 02:09
  • i.e. on mac, with or without shebang, it works. but on linux, with or without, it does not work. – Qiang Li Sep 09 '15 at 02:10
  • @QiangLi Please try to drop the `function` keyword, not all shells support it. – Some programmer dude Sep 09 '15 at 02:11
  • that's a great finding. Why so though? My not-working shell is `GNU bash, version 4.2.25(1)-release (x86_64-pc-linux-gnu)` – Qiang Li Sep 09 '15 at 02:18
  • could you help look at `http://stackoverflow.com/questions/32481734/shell-error-with-bash-bad-substitution-no-closing` too given your extensive experience with shell? That was a puzzling question to me too. thanks a lot! – Qiang Li Sep 09 '15 at 14:05