0

假设我创建了一个 my-npx-hello-world 存储库

它有以下文件

my-npx-hello-world/
      foo.sh
      index.sh
      package.json

package.json 有

  "bin": "./index.sh"

index.sh 调用 ./foo.sh 即

#!/bin/sh

echo "running foo"
./foo.sh

现在,当我尝试运行它时

# npx my-npx-hello-world
running foo
line 4: ./foo.sh: No such file or directory

那是因为它在我的 CWD 中而不是在 my-npx-hello-world 存储库中寻找 foo.sh。

我需要做什么才能让 index.sh 在同一个 repo 中执行 foo.sh 脚本。

4

1 回答 1

0

回答我自己的问题,我通过找到如下 CWD 解决了这个问题

BASEDIR=$(dirname "$0")/../lib/node_modules/my-npx-hello-worl

接着

cd $BASEDIR
./foo.sh
于 2019-02-09T18:31:10.257 回答