-
Notifications
You must be signed in to change notification settings - Fork 435
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
Fix OpenOS '/bin/sh cmd' failing due to lack of env table #3196
base: master-MC1.7.10
Are you sure you want to change the base?
Conversation
/bin/sh.lua should be able to execute a command passed as an argument, but failed to do so as sh.execute (in /lib/sh.lua) expects an env table. Meanwhile, /bin/source.lua passes said environment table when starting the sh process manually.
cenv = cargs[1] | ||
cargsStart = 2 | ||
end | ||
local result = table.pack(sh.execute(cenv, table.unpack(cargs, cargsStart))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be shortened a bit.
local cenv = _ENV
if type(cargs[1]) == "table" then
-- sh can also run as a manually started process (see /bin/source.lua)
cenv = table.remove(cargs, 1)
end
local result = table.pack(sh.execute(cenv, table.unpack(cargs)))
Also, what about using {...}
instead of table.pack(...)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as with skipping the arg with table.unpack
instead of using table.remove
, I figured I'd just stick to what's already being used and used table.pack
instead of {...}
, mixing multiple ways to achieve the same thing in the same chunk of code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are not completely identical. Using {...}
would pack all arguments into a table, whereas table.pack
actually also adds the additional key "n"
. Not that it matters in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL 😅 anyway, I've just pushed another commit implementing your proposed changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is up to @payonel anyway.
first of all, i greatly dislike that /bin/sh takes a table as an arg |
nope i dont care |
…. will not support #3196 at this time
…. will not support #3196 at this time
Well, guess this is not so simple to fix. |
/bin/sh.lua
should be able to execute a command passed as an argument, but currently fails to do so in interactive shells assh.execute
(in/lib/sh.lua
) expects an environment table as the first parameter:That environment table is given when running commands in the interactive shell, but is missing from the non-interactive
sh.execute
call.Meanwhile,
/bin/source.lua
passes an environment table as the first argument to/bin/sh.lua
when starting thesh
process manually.As such, I've decided to add a simple check if the first parameter is a table. If it is, it's assumed to be the environment table and won't be passed on. Otherwise
_ENV
will be used and all arguments will be passed on.This should maintain compatibility with any existing usages of
/bin/sh.lua
as a child process. Admittedly, I've only tested it locally by manipulating a copy of/bin/sh.lua
after installing OpenOS onto an OC computer.(Sidenote: I was not sure whether to remove the env table from the argument list, or whether to skip it when unpacking the arg list. I went with the second option as I thought it'd be preferred, given how returning does the same.)