Background: I'm trying to get nvm to setup up node correctly in a non-login shell via the shebang at the top of the node script.
The shebang for a node script in the login shell is:
#!/usr/bin/env node
This doesn't work for non-login shell so I want to do the equivalent of:
#!/usr/bin/env [[ -s $HOME/.nvm/nvm.sh ]] && source "$HOME/.nvm/nvm.sh" && node
But I'm not able to get the syntax correct (see below for error). I've tried several ways, including quoting the script or trying to run it bash -c. But each time I'm facing parsing errors.
The full script is:
#!/usr/bin/env node
const semver = require('semver');
console.log("Hello World! You're using " + process.version)
Errors:
in the login shell (where I don't need it)
❯ bin/nodesample.js
env: [[: No such file or directory
in the non login shell where I want to find a solution for
env: [[: No such file or directory
If I try #!/usr/bin/env "[[ -s $HOME/.nvm/nvm.sh ]] && source "$HOME/.nvm/nvm.sh" && node"
env: "[[: No such file or directory