Nik*_* R. 4 shell c cd-command posix
通配和外壳扩展是一回事吗?我正在通过编写自定义 shell 来学习 C,我也在学习 POSIX。现在我想知道是否是 POSIX 合规性cd -让您回归,这是否~意味着主目录?因为并非所有 shell 都可以做到这一点,而且我不知道是否需要 cd 命令的最小 POSIX 合规性。我使用的实现是
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;
}
Run Code Online (Sandbox Code Playgroud)