The |& syntax is using a non-standard token which is recognized by bash but not all shells. Such a construct is often called a bashism. If your shell is inadvertently invoked as a non-bash shell, then it is a syntax error. You can easily use a standardized construct for this:
npm test 2>&1 | grep -v '\[HPM\]'
Note that this is unusual. It seems odd to capture the stderr of npm, but perhaps you really do want to check if grep prints any lines. There's really no need to explicitly check $?, and your code would normally be written:
if ! npm test 2>&1 | grep -v '\[HPM\]'; then
: grep failed. Do something
fi
But again, this seems strange. grep -v will "fail" if it does not print any lines of text, and it will succeed otherwise. Perhaps you were expecting $? to contain the exit status of npm in your original code, but it does not. $? will be zero if grep prints any text, and non-zero otherwise.
./test.sh?|&syntax. Your life will be much easier if you usenpm test 2>&1 | grep ...npm test | grepand don't modify stderr.sh test.sh. Whenever I try./test.shit saysno such file or directory.|&is bash syntax, not sh.