minishell
Minishell Project for École 42
|
Builtin function for the "unset" command in the minishell project. More...
#include "minishell.h"
Functions | |
void | delete_variable (t_shell *shell, char *arg) |
Deletes an environment variable. | |
void | unset_arg (t_shell *shell, char *arg, int *fails) |
Unsets an environment variable or prints an error message. | |
int | unset (t_shell *shell, char **args) |
Executes the "unset" command to remove environment variables. | |
Builtin function for the "unset" command in the minishell project.
This file contains the implementation of the unset
builtin function for the minishell project. The unset
command is used to remove environment variables based on the provided arguments.
void delete_variable | ( | t_shell * | shell, |
char * | arg | ||
) |
Deletes an environment variable.
This function deletes an environment variable specified by its name (arg) from the shell's environment linked list. It finds the variable to delete and removes it from the linked list, freeing the associated memory.
[in,out] | shell | A pointer to the shell struct. |
[in] | arg | The name of the environment variable to delete. |
int unset | ( | t_shell * | shell, |
char ** | args | ||
) |
Executes the "unset" command to remove environment variables.
This function processes the "unset" command and removes the specified environment variables based on the provided arguments. It returns EXIT_SUCCESS
on success or EXIT_FAILURE
if any errors occurred.
[in,out] | shell | A pointer to the shell struct. |
[in] | args | An array of strings containing the arguments. |
void unset_arg | ( | t_shell * | shell, |
char * | arg, | ||
int * | fails | ||
) |
Unsets an environment variable or prints an error message.
This function unsets an environment variable specified by its name (arg) if it's a valid identifier (starts with an alphabetic character or '_'). If the identifier is not valid, it prints an error message and increments the failure count.
[in,out] | shell | A pointer to the shell struct. |
[in] | arg | The name of the environment variable to unset. |
[in,out] | fails | A pointer to the failure count. |