char *home = getenv("HOME");
if (!strcmp(t->argv[0], "cd")) {
if (!t->argv[1]) {
chdir(home);
}
if (chdir(t->argv[1])) {
perror(t->argv[1]);
}
}
what this is supposed to do is run the cd
command with the provided argument, and if there is no argument provided then return to the home directory. if i call cd
without an argument, chdir
prints "Bad address"
. i dont know why, considering i printed the value that getenv("HOME")
returns and entered that path manually in my shell and it worked fine. why does it work when i provide the value but not when getenv
provides it?
I also cant manually code a path for home either because it has to run on other machines. i need it to work with getenv("HOME")
.