-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenv.c
More file actions
30 lines (29 loc) · 1.11 KB
/
Copy pathenv.c
File metadata and controls
30 lines (29 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "Command.h"
void expand_variables(void) {
int i, j;
for (i = 0; i < num_commands; i++) {
for (j = 0; j < commands[i].argc; j++) {
if (commands[i].args[j][0] == '$') {
char *var_name = commands[i].args[j] + 1;
char *var_value = getenv(var_name);
free(commands[i].args[j]);
commands[i].args[j] = strdup(var_value ? var_value : "");
}
}
if (commands[i].input_file && commands[i].input_file[0] == '$') {
char *var_name = commands[i].input_file + 1;
char *var_value = getenv(var_name);
free(commands[i].input_file);
commands[i].input_file = strdup(var_value ? var_value : "");
}
if (commands[i].output_file && commands[i].output_file[0] == '$') {
char *var_name = commands[i].output_file + 1;
char *var_value = getenv(var_name);
free(commands[i].output_file);
commands[i].output_file = strdup(var_value ? var_value : "");
}
}
}