mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-05 23:18:08 +01:00
fix(command_not_found): unset or empty PATH leads to No such file or directory error
This commit is contained in:
parent
c756d3783f
commit
29bbb5e572
4 changed files with 48 additions and 6 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/03/27 16:21:56 by khais #+# #+# */
|
||||
/* Updated: 2025/04/22 15:38:00 by khais ### ########.fr */
|
||||
/* Updated: 2025/04/25 15:47:14 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -28,11 +28,23 @@
|
|||
#include "../../postprocess/expansion/expand_wildcard.h"
|
||||
#include "simple_cmd_execute_debug.h"
|
||||
#include "handle_redirections.h"
|
||||
#include "../../subst/simple_filename_exp_utils_utils.h"
|
||||
#include "../../subst/path_split.h"
|
||||
|
||||
static void command_not_found(t_simple_cmd *cmd, t_minishell *app)
|
||||
{
|
||||
char **path;
|
||||
|
||||
path = get_paths_array(app->env);
|
||||
if (path == NULL || path[0] == NULL)
|
||||
{
|
||||
ft_dprintf(STDERR_FILENO, "minishell: %s: No such file or directory\n",
|
||||
cmd->words->word->word);
|
||||
}
|
||||
else
|
||||
ft_dprintf(STDERR_FILENO, "minishell: %s: command not found\n",
|
||||
cmd->words->word->word);
|
||||
path_split_destroy(path);
|
||||
app->last_return_value = 127;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/24 17:56:47 by khais #+# #+# */
|
||||
/* Updated: 2025/04/24 18:00:33 by khais ### ########.fr */
|
||||
/* Updated: 2025/04/25 15:42:20 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -23,7 +23,7 @@
|
|||
** in the PATH environnement variable.
|
||||
** Returns NULL in case of an allocation error.
|
||||
*/
|
||||
static char **get_paths_array(t_env *env)
|
||||
char **get_paths_array(t_env *env)
|
||||
{
|
||||
char **path_array;
|
||||
t_env *path_node;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/24 17:57:22 by khais #+# #+# */
|
||||
/* Updated: 2025/04/24 18:00:56 by khais ### ########.fr */
|
||||
/* Updated: 2025/04/25 15:42:31 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -16,5 +16,6 @@
|
|||
# include "../minishell.h"
|
||||
|
||||
char *filepath_from_env(char *filename, t_minishell *app);
|
||||
char **get_paths_array(t_env *env);
|
||||
|
||||
#endif // SIMPLE_FILENAME_EXP_UTILS_UTILS_H
|
||||
|
|
|
|||
29
test.sh
29
test.sh
|
|
@ -1196,4 +1196,33 @@ expecting <<EOF
|
|||
A=
|
||||
EOF
|
||||
|
||||
when_run <<EOF "unset PATH leads to No such file or directory error"
|
||||
export EXTRAPATH="$(dirname $(which ls))"
|
||||
qwertyuiop
|
||||
unset PATH
|
||||
qwertyuiop
|
||||
export PATH=""
|
||||
qwertyuiop
|
||||
export PATH=":"
|
||||
qwertyuiop
|
||||
export PATH="::"
|
||||
qwertyuiop
|
||||
export PATH="\$EXTRAPATH"
|
||||
qwertyuiop
|
||||
export PATH=":\$EXTRAPATH"
|
||||
qwertyuiop
|
||||
export PATH="\$EXTRAPATH:"
|
||||
qwertyuiop
|
||||
EOF
|
||||
expecting <<EOF
|
||||
minishell: qwertyuiop: command not found
|
||||
minishell: qwertyuiop: No such file or directory
|
||||
minishell: qwertyuiop: No such file or directory
|
||||
minishell: qwertyuiop: command not found
|
||||
minishell: qwertyuiop: command not found
|
||||
minishell: qwertyuiop: command not found
|
||||
minishell: qwertyuiop: command not found
|
||||
minishell: qwertyuiop: command not found
|
||||
EOF
|
||||
|
||||
finalize
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue