jovanbulck / jsh

A basic UNIX shell implementation in C
GNU General Public License v3.0
30 stars 10 forks source link

cd built_in and PWD env var #22

Open jovanbulck opened 9 years ago

jovanbulck commented 9 years ago

cd also updates the PWD env var, but the supplied dir can also be relative (. or ..) and should then be resolved in the PWD var. Here's the code:

        case CD: ; // (hackhackhack to allow declarions inside a switch)
            char *dir;
            if (comd->length == 1)
                dir = getenv("HOME");
            else {
                CHK_ARGC("cd",1);
                dir = comd->cmd[1];
            }
            CHK_ERR(chdir(dir), "cd");
            setenv("PWD", dir, 1);   // BUG: dir can be relative and should then be resolved
            return EXIT_SUCCESS;
            break;
jovanbulck commented 9 years ago

See issue #51 for further discussion