提交 9863fea7 创建 作者: rsc's avatar rsc

clumsy cd

上级 fbd8857d
...@@ -157,6 +157,14 @@ main(void) ...@@ -157,6 +157,14 @@ main(void)
// Read and run input commands. // Read and run input commands.
while(getcmd(buf, sizeof(buf)) >= 0){ while(getcmd(buf, sizeof(buf)) >= 0){
if(buf[0] == 'c' && buf[1] == 'd' && buf[2] == ' '){
// Clumsy but will have to do for now.
// Chdir has no effect on the parent if run in the child.
buf[strlen(buf)-1] = 0; // chop \n
if(chdir(buf+3) < 0)
printf(2, "cannot cd %s\n", buf+3);
continue;
}
if(fork1() == 0) if(fork1() == 0)
runcmd(parsecmd(buf)); runcmd(parsecmd(buf));
wait(); wait();
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论