-
Notifications
You must be signed in to change notification settings - Fork 8
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
shift function does not work #35
Comments
Is this what you mean?
|
yes ... Note - BASH_SOURCE[0] is the abs path to the script (versus $0 which is how the script was invoked) |
Shell variables (values set specifically by the shell itself but not exported) probably won't work. Not sure if it makes sense to implement them in ShellJS or here, but I'm open to discussing it.
Note that some of these are environmental variables, which will work 😄. Although, apparently
Some are supported, take a look at #4. Help is appreciated. |
I agree most Shell variables are not relevant. I thought, however, that the ones i mentioned might be of use. BASH_SOURCE[0] is AFAIK the only reliable way to get an absolute path to the folder containing the shell script, which i use sometimes if i need to have additional/optional related files and/or scripts (which within a node app could be handled differently, but in terms of transpiling existing bash code.) Although the full array of sources is probably not needed. And, of course, node provides __dirname (so maybe, BASH_SOURCE[0] === __dirname + require(__dirname + '/package.json').name)?) The other one is RANDOM which i guess is covered functionally by Math.random(). I was thinking that in terms of transpiling mapping references to RANDOM to something like Math.floor(Math.random() * 32768)) would be useful. I can't say i've ever used PPID, but it's not easily computable at the shell level except by parsing some process stat output which is system dependent. |
@Brassrat can you link to docs for each of these? |
BASH_SOURCE, PWD, RANDOM, PPID, HOME are documented in bash man page. BASH_SOURCE I think only BASH_SOURCE[0] make sense for shelljs-transpiler. PPID The process ID of the shell's parent. This variable is readonly. if you google 'bash pwd' you get pages like [https://unix.stackexchange.com/questions/173916/is-it-better-to-use-pwd-or-pwd] which discuss use of $(pwd) vs $PWD. |
The 'shift' function is implemented via exec('shift') - but this doesn't/can't/shouldn't change the process.argv array. thus the value of, e.g., $1 does not change after shift.
Seems that process.argv needs to be copied and $N references are to this copy.
'shift M' functions would replace this copy by a slice of it thus changing the values associated with $K
The text was updated successfully, but these errors were encountered: