feat(exec): Added the unset builtin
This commit is contained in:
parent
17f8b918c8
commit
1f4742e17b
1 changed files with 20 additions and 0 deletions
|
|
@ -125,6 +125,7 @@ static int try_builtin(char **argv, struct hash_map *vars);
|
||||||
|
|
||||||
static int builtin_break(char **argv);
|
static int builtin_break(char **argv);
|
||||||
static int builtin_continue(char **argv);
|
static int builtin_continue(char **argv);
|
||||||
|
static int builtin_unset(char **argv, struct hash_map *vars);
|
||||||
|
|
||||||
static int exec_assignment(struct list *assignment_list, struct hash_map *vars)
|
static int exec_assignment(struct list *assignment_list, struct hash_map *vars)
|
||||||
{
|
{
|
||||||
|
|
@ -487,6 +488,23 @@ static int builtin_cd(char **argv, struct hash_map *vars)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int builtin_unset(char **argv, struct hash_map *vars)
|
||||||
|
{
|
||||||
|
if (!argv)
|
||||||
|
return 0;
|
||||||
|
for (int i = 1; argv[i]; i++)
|
||||||
|
{
|
||||||
|
const char *name = argv[i];
|
||||||
|
if (name == NULL || name[0] == '\0')
|
||||||
|
continue;
|
||||||
|
// remove from shell variables
|
||||||
|
hash_map_remove(vars, name);
|
||||||
|
// remove from environment variables
|
||||||
|
unsetenv(name);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Tries to execute a builtin command if the command matches a builtin
|
* @brief Tries to execute a builtin command if the command matches a builtin
|
||||||
*
|
*
|
||||||
|
|
@ -500,6 +518,8 @@ static int try_builtin(char **argv, struct hash_map *vars)
|
||||||
|
|
||||||
if (strcmp(argv[0], "echo") == 0)
|
if (strcmp(argv[0], "echo") == 0)
|
||||||
return builtin_echo(argv);
|
return builtin_echo(argv);
|
||||||
|
if (strcmp(argv[0], "unset") == 0)
|
||||||
|
return builtin_unset(argv, vars);
|
||||||
if (strcmp(argv[0], "true") == 0)
|
if (strcmp(argv[0], "true") == 0)
|
||||||
return builtin_true(argv);
|
return builtin_true(argv);
|
||||||
if (strcmp(argv[0], "false") == 0)
|
if (strcmp(argv[0], "false") == 0)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue