]> Devi Nivas Git - cs3210-lab1.git/commitdiff
clumsy cd
authorrsc <rsc>
Thu, 30 Aug 2007 18:30:26 +0000 (18:30 +0000)
committerrsc <rsc>
Thu, 30 Aug 2007 18:30:26 +0000 (18:30 +0000)
sh.c

diff --git a/sh.c b/sh.c
index 7a7c4c20cb9278807c7f5198a2aa257613a7ff1c..100bbdcf97604d1c5d59aadca7dd0f51c947fc10 100644 (file)
--- a/sh.c
+++ b/sh.c
@@ -157,6 +157,14 @@ main(void)
   
   // Read and run input commands.
   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)
       runcmd(parsecmd(buf));
     wait();