minishell
Minishell Project for École 42
Loading...
Searching...
No Matches
unset_builtin.c File Reference

Builtin function for the "unset" command in the minishell project. More...

#include "minishell.h"
Include dependency graph for unset_builtin.c:

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.
 

Detailed Description

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.

Function Documentation

◆ delete_variable()

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.

Parameters
[in,out]shellA pointer to the shell struct.
[in]argThe name of the environment variable to delete.

◆ unset()

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.

Parameters
[in,out]shellA pointer to the shell struct.
[in]argsAn array of strings containing the arguments.
Returns
An exit status (EXIT_SUCCESS on success, or EXIT_FAILURE on failure).

◆ unset_arg()

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.

Parameters
[in,out]shellA pointer to the shell struct.
[in]argThe name of the environment variable to unset.
[in,out]failsA pointer to the failure count.