added first builtin
corrected binary execution + added echo
This commit is contained in:
35
srcs/exec.c
Normal file
35
srcs/exec.c
Normal file
@@ -0,0 +1,35 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* exec.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/27 15:32:29 by tmaze #+# #+# */
|
||||
/* Updated: 2018/11/27 16:36:48 by tmaze ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
#define S_BIN 1
|
||||
|
||||
int exec_cmd(char **argv, char **env)
|
||||
{
|
||||
size_t i;
|
||||
static t_builtin builtins[S_BIN] = {{"echo", &cmd_echo}};
|
||||
|
||||
/* ,{"cd", &cmd_cd}, */
|
||||
/* {"setenv", &cmd_senv},{"unsetenv", &cmd_senv}, {"env", &cmd_env}}; */
|
||||
|
||||
i = 0;
|
||||
while (i < S_BIN)
|
||||
{
|
||||
if (ft_strcmp(argv[0], builtins[i].cmd) == 0)
|
||||
return ((*(builtins[i].f))(argv, env));
|
||||
i++;
|
||||
}
|
||||
execve(argv[0], argv, env);
|
||||
ft_putendl("minishell: error");
|
||||
return (1);
|
||||
}
|
Reference in New Issue
Block a user