0

Say I create a my-npx-hello-world repo

it has the following files

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

the package.json has

  "bin": "./index.sh"

the index.sh calls ./foo.sh i.e.

#!/bin/sh

echo "running foo"
./foo.sh

Now, when I try to run this

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

That is because it is looking for foo.sh in my CWD and not in the my-npx-hello-world repo.

What do I need to do so I can have the index.sh execute the foo.sh script in the same repo.

molicule
  • 5,481
  • 3
  • 29
  • 40

1 Answers1

0

Answering my own question, I resolved this by finding the CWD as below

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

and then

cd $BASEDIR
./foo.sh
molicule
  • 5,481
  • 3
  • 29
  • 40