When using cd it will change directory to home if not specifying directory
This commit is contained in:
@@ -1,12 +1,13 @@
|
|||||||
// C Program to design a shell in Linux
|
// C Program to design a shell in Linux
|
||||||
#include<stdio.h>
|
#include <stdio.h>
|
||||||
#include<string.h>
|
#include <string.h>
|
||||||
#include<stdlib.h>
|
#include <stdlib.h>
|
||||||
#include<unistd.h>
|
#include <unistd.h>
|
||||||
#include<sys/types.h>
|
#include <sys/types.h>
|
||||||
#include<sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include<readline/readline.h>
|
#include <readline/readline.h>
|
||||||
#include<readline/history.h>
|
#include <readline/history.h>
|
||||||
|
#include <pwd.h>
|
||||||
|
|
||||||
#define MAXCOM 1000 // max number of letters to be supported
|
#define MAXCOM 1000 // max number of letters to be supported
|
||||||
#define MAXLIST 100 // max number of commands to be supported
|
#define MAXLIST 100 // max number of commands to be supported
|
||||||
@@ -126,8 +127,14 @@ int ownCmdHandler(char** parsed)
|
|||||||
case 1:
|
case 1:
|
||||||
exit(0);
|
exit(0);
|
||||||
case 2:
|
case 2:
|
||||||
chdir(parsed[1]);
|
if(parsed[1]){
|
||||||
return 1;
|
chdir(parsed[1]);
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
char *home = getenv("HOME");
|
||||||
|
chdir(home);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user