将参数从npm脚本传递给bash shell脚本

时间:2017-05-15 10:22:00

标签: bash npm

的package.json:

"scripts": {
  "test": "bash test.sh"
},

test.sh:

#!/bin/bash
for i in "$@"
do
case $i in
    -l=*|--lib=*)
    LIBPATH="${i#*=}"
    shift # past argument=value
    ;;
    --default)
    DEFAULT=YES
    shift # past argument with no value
    ;;
    *)
            # unknown option
    ;;
esac
done
echo "LIBRARY PATH    = ${LIBPATH}"

尝试调用:npm run test -l=/usr/lib,虽然无效。

1 个答案:

答案 0 :(得分:3)

DERP。错过了两个--

npm run install -- -l=/usr/lib
相关问题