diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/shell.lua b/src/main/resources/assets/computercraft/lua/rom/programs/shell.lua index 8be9cbe06..ef071be64 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/shell.lua +++ b/src/main/resources/assets/computercraft/lua/rom/programs/shell.lua @@ -130,8 +130,12 @@ local function run( _sCommand, ... ) end multishell.setTitle( multishell.getCurrent(), sTitle ) end + local sDir = fs.getDir( sPath ) - local result = os.run( createShellEnv( sDir ), sPath, ... ) + local env = createShellEnv( sDir ) + env[ "arg" ] = { [0] = _sCommand, ... } + local result = os.run( env, sPath, ... ) + tProgramStack[#tProgramStack] = nil if multishell then if #tProgramStack > 0 then diff --git a/src/test/resources/test-rom/spec/programs/shell_spec.lua b/src/test/resources/test-rom/spec/programs/shell_spec.lua new file mode 100644 index 000000000..9d0a7d237 --- /dev/null +++ b/src/test/resources/test-rom/spec/programs/shell_spec.lua @@ -0,0 +1,17 @@ +describe("The shell", function() + describe("shell.run", function() + it("sets the arguments", function() + local handle = fs.open("test-files/out.txt", "w") + handle.writeLine("_G.__arg = arg") + handle.close() + + shell.run("/test-files/out.txt", "arg1", "arg2") + fs.delete("test-files/out.txt") + + local args = _G.__arg + _G.__arg = nil + + expect(args):same { [0] = "/test-files/out.txt", "arg1", "arg2" } + end) + end) +end)