1. write a shell in C Programming with builtin, that will support the following
ID: 673548 • Letter: 1
Question
1. write a shell in C Programming with builtin, that will support the following commands:
A. mycd <directory> - (change the current default directory to <directory>. if the <directory> arguement is not present, report the current directory. If the directory does not exist, an appropiatr error should be reported. this command should also change the PWD evvironment variables.)
B. myclr - clear the screen.
C. mydir <directory> - list the contents of directory <directory>
D. myenviron - list all the environment strings.
E. myecho - <comment> - display <comment> on the display followed by a new line (multiple spaces/tabs may be reduced to a singlr space).
F. myhelp - display the user manual using the 'more' filter.
G. mypause - pause operation of the shell until 'Enter' is pressed.
H. myquit - quit the shell
I. The shell environment should contain 'shell=<pathname>/myshell where <pathname> /myshell is the full path for the shell.
2. All other command line input is interpreted as program invocation which should be done by the shell 'fork'ing and 'exec'ing the program as its own child process.
3. The command line prompt must contain the pathname of the current directory.
Explanation / Answer
#include #include #include #include #define FALSE 0 #define TRUE !FALSE extern int alphasort(); char pathname[MAXPATHLEN]; main() { int count,i; struct direct **files; int file_select(); if (getwd(pathname) == NULL ) { printf("Error getting path "); exit(0); } printf("Current Working Directory = %s ",pathname); count = scandir(pathname, &files, file_select, alphasort); /* If no files found, make a non-selectable menu item */ if (count d_name, ".") == 0) || (strcmp(entry->d_name, "..") == 0)) return (FALSE); else return (TRUE); }Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.