Abstract: Design, implement, explain, test, and debug a simple shell, a complete but simple command-line interpreter named cli.

Detail: Design, implement, document, test and run a simple shell, known here as a command-line interpreter (cli). Your cli is invoked via the cli command plus possible arguments; these commands are Unix commands to be executed under the Unix (or Linux) OS. These commands are separated from one another by commas, and each may in turn have arguments. Cli 'knows' a list of commands a-priori. When invoked cli checks, whether the first command is included in its predefined list. If so, cli states that with a brief message. If not, a contrary message is emitted, stating that this is not one the predefined supported commands. After the message, cli executes all commands in the order listed. After executing the last command, cli prints the current working directory, i.e. it acts as if the pwd command had been executed. A Sample run is shown further below.

The various commands of cli are separated from one another by commas. Possible parameters of any one command are separated from the command itself (and from possible further parameters) by white space. White space consists of blanks, tabs, or a combination, but at least 1 blank space. Here some sample run commands:

./cli pwd
./cli rm –f temp, mv temp ../temp1
./cli ls –la
./cli rm a.out, gcc sys.c, cp a.out cli

Cli starts out identifying itself, you the author, and the release date. Then cli prints the list of all predefine commands. Finally, cli executes all commands listed after the cli invocation. For your own debug effort, test your solution with numerous correct and also wrong inputs, including commas omitted, multiple commas, leading commas, illegals commands, other symbols instead of commas etc.

The output of the cli command "cli pwd" or ./cli pwd should be as shown below, assuming your current working directory is ./classes_Sac_State/csc139. Here the output of a sample run with a single command line argument:

herbertmayer$ ./cli pwd
hgm cli 4/12/2004
Legal commands: cd execv exit fork gcc ls man more mv rm pwd sh touch which $PATH
2 strings passed to argv[]
next string is 'pwd'
new string is 'pwd '
1st cmd 'pwd' is one of predefined.
/Users/herbertmayer/herb/academia/classes_Sac_State/csc139

Here the output of another sample run, also with a single cli:

herbertmayer$ ./cli ls
hgm cli 4/12/2004
Legal commands: cd execv exit fork gcc ls man more mv rm pwd sh touch which $PATH
2 strings passed to argv[]
next string is 'ls'
new string is 'ls '
1st cmd 'ls' is one of predefined.
admin cli.c sac_state_busovaca
backup_1_24_2020 docs sac_state_hw
backup_3_9_2020 grades sac_state_shobaki
cli l_notes
/Users/herbertmayer/herb/academia/classes_Sac_State/csc139

Interpretation of commands that cli handles can proceed through one of several means; you select. For example, you may execute fork and execv. Or you may invoke system() executed from inside your C/C++ program. It is recommended that you use library function system() for your implementation.

List of all commands supported by your cli:

char * cmds[ MAX_LIST ] = // MAX_LIST being 15, defined elsewhere
{
"cd",
"execv",
"exit",
"fork",
"gcc",
"ls",
"man",
"more",
"mv",
"rm",
"pwd",
"sh",
"touch",
"which",
"$PATH"
};
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.