#include #include #include #include #include #include #include #include #include #include #define Size 128 char commands[Size][Size]; int analyse_commands(char command[Size]); void Do_command(int num); void for_pipe(int left, int right); void for_redi(int left, int right); void for_andand(int left, int right); int main() { char buf[Size],username[20],hostname[20],path[64]; while(1){ struct passwd* pwd=getpwuid(getuid()); strcpy(username,pwd->pw_name); gethostname(hostname,20); getcwd(path,64); printf("MyShell_%s_%s_%s$",username,hostname,path); fgets(buf,Size,stdin); int len=strlen(buf); if (len!=Size) buf[len-1]='\0'; int num=analyse_commands(buf); if (num!=0) { if (strcmp(commands[0],"exit") == 0) exit(0); else if (strcmp(commands[0],"cd") == 0) chdir(commands[1]); else Do_command(num); } } } int analyse_commands(char buf[Size]) { int num=0,row=0,col=0; int len=strlen(buf); for (; row")==0){ flagout++; if(i+1>")==0){ flagoo++; if(i+10) write(fnew,&temp,sizeof(temp)); close(fold); close(fnew); remove(commands[idxMV+1]); exit(0); } int cpidtmp=getpid(); write(fdpid[1],&cpidtmp,sizeof(cpidtmp)); char* tcomm[Size]; for (int idx=0; idx