Reference no: EM132206550
Write a minishell using the template code below
* Implement function type_prompt( )
* Making read_command( ) work could be a little more involved.
* Note that the command contains the first argument, the file name, while parameters contain all information of input line in any arrays of strings, including the executable file name, same as in the command, as its first string. For example the command ssh -1 joe pluto.hood.edu is stored as
parameter[0]: /usr /bin/ ssh
parameter[1]: -1
parameter[2]: joe
parameter[3]: pluto.hood.edu
parameter[4]: NULL
Donot forget to initialize a dynamic string, before filling it with characters.
Some of the most commonly used commands are built in command handled by shell,for example, exit. You will not be able to test these commands unless you implement within your shell program. Built in commands is processed by the shell program without invoking the fork-exec() loop.
#define TRUE 1
while (TRUE) { /* repeat forever */
type prompt( ); /* display prompt on the screen */
read command(command, parameters); /* read input from terminal */
if (for k() != 0) { / * fork off child process */
/* Parent code. */
waitpid(-1, &status, 0); /* wait for child to exit */
}else {
/* Child code. */
execve(command, parameters, 0); /* execute command */ }
}