Shell built-in commands, unlike legacy executables such as /bin/ls or /usr/bin/vim, are internal features of a shell that the user may invoke. For example, alias (to create a shortcut such as ‘l’ for ‘ls’), cd, history are among common built-in commands supported by most shells. When a user enters a command, a shell must first check if it is a built-in command in which case forking a child to load and run a legacy executable is not required. If the entered command is not built-in, then a shell assumes that it is a binary executable that needs to found and executed by a worker process. Extending built-in commands into a programming language, called shell scripts, is a popular way to manage and automate tasks on UNIX based operating systems such as Linux and MacOS.
Use the code of main4.c as a starting point to extend its capability to support the following built-in commands:
is a string that is stored in a memo note. Implement the memo note as a 1-D array of maximum size 10, char *memnote, where each element is a pointer to a string. Use malloc() to allocate just enough memory to store the string . When memnote is full, cycle to the beginning and overwrite memnote with the new string. Hence memnote is a circular array that overwrites the oldest element if space is full. Keep track of the newest and oldest memo note so that when the user enters the command ‘mem’ without a string then the memo note strings are output by recency, with the newest first and the oldest last, by the order the user has added them to the memnote string array.
The command d asks that the shell delay running the legacy executable
The command x without arguments means to terminate the shell. The shell prints a suitable message to stdout, then calls exit(0) to terminate.
Although main4.c serves as the main skeleton code, implement the built-in features supported by the shell, call it mysh, in a modular fashion making calls to functions that are put in their own file in a folder v12. Create a README text file that describes what each file in a folder v12 contains and its role. Use a Makefile to compile your code. 20 points out of 150 will be assigned for modularity, clarity, and style. Although not necessary, you may use string processing library functions. The library function atoi() which converts a number represented as a string (e.g., “3075”) into an integer (3075) may be useful. Look up its man page if you decide to use it. Test and verify that mysh works correctly. the code should run under Mac terminal.