diff --git a/lcmd.c b/lcmd.c index f5fd6fdd..83cd0fc4 100644 --- a/lcmd.c +++ b/lcmd.c @@ -1205,8 +1205,7 @@ int lushCmd_interactive (lua_State *L) { if (nstages > 1) { exec_pipeline(L, stages, nstages, 1); free(stages[0]); - lua_setglobal(L, "_"); - return 0; + goto set_and_return; } /* single stage */ @@ -1220,21 +1219,22 @@ int lushCmd_interactive (lua_State *L) { dynbuf_init(&empty_out); dynbuf_init(&empty_err); push_result_table(L, 0, &empty_out, &empty_err); - lua_setglobal(L, "_"); - return 0; + goto set_and_return; } /* check for shell builtin */ if (try_builtin(L, &pa)) { free_argv(&pa); - lua_setglobal(L, "_"); - return 0; + goto set_and_return; } fork_exec_single(L, &pa, 0); free_argv(&pa); - lua_setglobal(L, "_"); - return 0; + +set_and_return: + lua_pushvalue(L, -1); /* duplicate result table */ + lua_setglobal(L, "_"); /* pop one copy into _ */ + return 1; /* return the other */ }