aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar BanceDev 2024-09-23 15:56:03 -0400
committerGravatar BanceDev 2024-09-23 15:56:03 -0400
commit6d0ff4d8db9700ca98675fb3816144801bc2b687 (patch)
treedbb706bb5d08a511bf460f1717e6db2b0ce67aab
parentimplemented background process operator (diff)
fixed operator chaining to handle commands terminating with an operator
-rw-r--r--src/lush.c19
1 files changed, 5 insertions, 14 deletions
diff --git a/src/lush.c b/src/lush.c
index 3318807..f851b2f 100644
--- a/src/lush.c
+++ b/src/lush.c
@@ -1092,17 +1092,13 @@ int lush_execute_chain(lua_State *L, char ***commands, int num_commands) {
for (int i = 0; i < num_actions; i++) {
// Determine the operator type between commands
- if (i < num_actions - 1) {
+ if (i < num_actions && commands[1] != NULL) {
int op_type = is_operator(commands[1][0]);
- // Handle '&&' operator
if (op_type == OP_AND && last_result != 0) {
commands += 2;
continue;
- }
-
- // Handle '|', build pipe array
- if (op_type == OP_PIPE) {
+ } else if (op_type == OP_PIPE) {
char ***pipe_commands =
malloc(sizeof(char **) * (num_actions - i));
int pipe_count = 0;
@@ -1124,20 +1120,15 @@ int lush_execute_chain(lua_State *L, char ***commands, int num_commands) {
free(pipe_commands);
commands += 2;
continue;
- }
- // Handle '&' operator for background execution
- if (op_type == OP_BACKGROUND) {
-
+ } else if (op_type == OP_BACKGROUND) {
run_command_background(L, commands);
commands += 2;
continue;
}
}
- if (!is_operator(commands[0][0])) {
- last_result = run_command(L, commands);
- commands += 2;
- }
+ last_result = run_command(L, commands);
+ commands += 2;
}
return 1;