Artificial intelligent assistant

POSIX compliance of the cd program? Is globbing and shell expansion same thing? I'm learning C by writing a custom shell and I'm also learning POSIX. Now I wonder if it is POSIX compliance that `cd -` takes you back and that `~` means home directory? Because not all shells can do that, and I don't know if it is required for a minimal POSIX compliance of the cd command. The implementation I use is int do_cd(int argc, const char **argv) { const char *path; if (argc > 1) { path = argv[1]; } else { path = getenv("HOME"); if (path == NULL) { fprintf(stderr, "No HOME environment variable\n"); return 1; } } if (chdir(path) < 0) { perror(path); return 1; } return 0; }

Tilde expansion is part of shell command processing, not part of `cd`. `cd` sees the already-expanded path as its argument.

POSIX requires `cd -` to be equivalent to `cd "$OLDPWD" && pwd`. `OLDPWD` must be set by `cd` if `PWD` exists at the time of running the command.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy eba78a730201b08659fa7ffc3664190b