mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
cd: with no arg, go to $HOME
This commit is contained in:
parent
e93e6efb93
commit
d66ca10a0c
2 changed files with 14 additions and 4 deletions
|
|
@ -6,13 +6,13 @@
|
||||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/03/31 16:20:17 by khais #+# #+# */
|
/* Created: 2025/03/31 16:20:17 by khais #+# #+# */
|
||||||
/* Updated: 2025/03/31 16:32:52 by khais ### ########.fr */
|
/* Updated: 2025/03/31 16:39:30 by khais ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "builtins.h"
|
#include "builtins.h"
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "libft.h"
|
#include "../../env/env_manip.h"
|
||||||
#include "../../ft_errno.h"
|
#include "../../ft_errno.h"
|
||||||
|
|
||||||
static void ft_chdir(char *path, t_minishell *app)
|
static void ft_chdir(char *path, t_minishell *app)
|
||||||
|
|
@ -30,12 +30,13 @@ static void ft_chdir(char *path, t_minishell *app)
|
||||||
t_builtin_type builtin_cd(t_simple_cmd *cmd, t_minishell *app)
|
t_builtin_type builtin_cd(t_simple_cmd *cmd, t_minishell *app)
|
||||||
{
|
{
|
||||||
t_worddesc *arg;
|
t_worddesc *arg;
|
||||||
|
char *home;
|
||||||
|
|
||||||
arg = wordlist_get(cmd->words, 1);
|
arg = wordlist_get(cmd->words, 1);
|
||||||
if (arg == NULL)
|
if (arg == NULL)
|
||||||
{
|
{
|
||||||
app->last_return_value = 1;
|
home = env_get_val(app->env, "HOME");
|
||||||
ft_dprintf(STDERR_FILENO, "TODO: cd to $HOME\n");
|
ft_chdir(home, app);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ft_chdir(arg->word, app);
|
ft_chdir(arg->word, app);
|
||||||
|
|
|
||||||
9
test.sh
9
test.sh
|
|
@ -188,6 +188,15 @@ minishell: cd: Permission denied
|
||||||
/tmp/dir.minishell
|
/tmp/dir.minishell
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
HOME=/tmp/dir.minishell/fakehome when_run <<EOF "cd with no arguments goes to \$HOME"
|
||||||
|
mkdir fakehome
|
||||||
|
cd
|
||||||
|
pwd
|
||||||
|
EOF
|
||||||
|
expecting <<EOF
|
||||||
|
/tmp/dir.minishell/fakehome
|
||||||
|
EOF
|
||||||
|
|
||||||
when_run <<EOF "quoted parentheses are not operators"
|
when_run <<EOF "quoted parentheses are not operators"
|
||||||
echo unclosed '('
|
echo unclosed '('
|
||||||
EOF
|
EOF
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue