Reputation: 40522
/home/karl/myapp/path.sh:
#!/bin/bash
currentDir=$(
cd $(dirname "$0")
pwd
)
echo $currentDir
The script above echos the absolute path. I'd like to set the NODE_PATH variable as seen below with the echo'd value.
NODE_PATH=path.sh ./node_modules/.bin/mocha -r babel-register -r babel-polyfill --reporter spec
At the moment NODE_PATH is actually set to the string "path.sh" and not the absolute path that it echos.
So I'd like the result to be the same as NODE_PATH=/home/karl/myapp/ ./node_modules/.bin/mocha -r babel-register -r babel-polyfill --reporter spec
as an example.
Any ideas?
I've also tried the following: bash path.sh | NODE_PATH="$currentDir" ./node_modules/.bin/mocha -r babel-register -r babel-polyfill --reporter spec
Upvotes: 0
Views: 1746
Reputation: 40522
With help from Arif Khans answer I was able to come up with the three following:
NODE_PATH="$(dirname $(readlink -f ./path.sh))" ./node_modules/.bin/mocha -r babel-register -r babel-polyfill --reporter spec
NODE_PATH="$(bash path.sh)" ./node_modules/.bin/mocha -r babel-register -r babel-polyfill --reporter spec
NODE_PATH="$(pwd)" ./node_modules/.bin/mocha -r babel-register -r babel-polyfill --reporter spec
Upvotes: 0
Reputation: 5158
you can do it by executing the below command:
NODE_PATH=`./p.sh`'./node_modules/.bin/mocha -r babel-register -r babel-polyfill --reporter spec'
whatever is in between `` is basically executing that particular command and then append what is needed.
Upvotes: 0
Reputation: 5069
By default, it will be consider as string. You need to inside $(COMMAND)
like in your case "$(sh path.sh)"
. So complete command will be
NODE_PATH="$(sh path.sh)" ./node_modules/.bin/mocha -r babel-register -r babel-polyfill --reporter spec
Hope this will help you
Upvotes: 1