added basic env & setenv commands
This commit is contained in:
45
srcs/cmd_cd.c
Normal file
45
srcs/cmd_cd.c
Normal file
@@ -0,0 +1,45 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* cmd_cd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/01/07 16:44:40 by tmaze #+# #+# */
|
||||
/* Updated: 2019/01/13 17:00:19 by tmaze ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
int cmd_cd(char **argv, t_list **env)
|
||||
{
|
||||
int i;
|
||||
int ret;
|
||||
char *path;
|
||||
t_list *tmp;
|
||||
|
||||
ret = 0;
|
||||
i = 0;
|
||||
tmp = *env;
|
||||
path = NULL;
|
||||
if (!argv[1])
|
||||
{
|
||||
while (tmp )
|
||||
{
|
||||
if (ft_strcmp(((t_envelem*)(tmp->content))->key, "HOME") == 0)
|
||||
{
|
||||
path = ((t_envelem*)(tmp->content))->val;
|
||||
break ;
|
||||
}
|
||||
tmp = tmp->next;
|
||||
}
|
||||
if (path == NULL)
|
||||
return (1);
|
||||
}
|
||||
else
|
||||
path = argv[1];
|
||||
ft_putendl(path);
|
||||
ret = chdir(path);
|
||||
return (ret);
|
||||
}
|
Reference in New Issue
Block a user