Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transpile references to BASH_SOURCE variable #36

Open
Brassrat opened this issue Nov 30, 2018 · 5 comments
Open

Transpile references to BASH_SOURCE variable #36

Brassrat opened this issue Nov 30, 2018 · 5 comments

Comments

@Brassrat
Copy link

Seems that $0 is like 'sh'?
shouldn't it be the path to the '.js' file?
preferably some absolute version of the path to the js file?

@nfischer
Copy link
Owner

nfischer commented Dec 2, 2018

I think it's the path to the script, as specified on the CLI:

$ cat print0.sh
#!/bin/bash
echo $0
$ bash print0.sh # notice the output is exactly what I type here
print0.sh
$ bash ./print0.sh # again, it prints whatever I typed
./print0.sh

So, it's not guaranteed to be an absolute path.

@Brassrat
Copy link
Author

Brassrat commented Dec 3, 2018

yes $0 is not guaranteed to be an absolute path in BASH - for that one uses either BASH_SOURCE or something like (cd -P $0)

@nfischer
Copy link
Owner

nfischer commented Dec 4, 2018

FWIW I think we implement this correctly. We translate $0 to process.argv[1], which is the path to the script file. Note that process.argv[0] is the path to NodeJS itself.

Closing this because I think it's WAI, but let me know if I'm mistaken.

@Brassrat
Copy link
Author

Brassrat commented Dec 4, 2018

i suggested implementing $0 as the absolute path to obviate the need to support BASH_SOURCE[0].
Admittedly, node provides __dirname.

@nfischer nfischer changed the title what should the value of $0 be? Transpile references to BASH_SOURCE variable Dec 5, 2018
@nfischer
Copy link
Owner

nfischer commented Dec 5, 2018

I think $0 is right as-is, but I might accept a PR for BASH_SOURCE, if you know how to implement all the entries and can point to docs.

Renaming this issue to reflect that.

@nfischer nfischer reopened this Dec 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants