Mini Shell - How to create in C - Unix HowTo
This is a discussion on Mini Shell - How to create in C - Unix HowTo ; I am looking for insights on how to create a mini shell in C. I am learning to program in C on linux and my mentor gave me this as an advanced assignment. The mini shell created should accept commands ...
Mini Shell - How to create in C
I am looking for insights on how to create a mini shell in C. I am learning to program in C on linux and my mentor gave me this as an advanced assignment. The mini shell created should accept commands and execute them as programmed.
1. Mini Shell should accept a command
2. Mini Shell should execute the command
3. Mini Shell should terminate on an exit command
1. ls -> List files in current directory in mini shell
2. cd -> change directory in mini shell
3. exit -> exit from shell
Any help in creating this mini shell would be appreciated
Re: Mini Shell - How to create in C
While I will not give you the code for mini shell, [ that you can anyway find on google ], let me give you the basic idea and the pseudo code based on which you can write your own mini shell.
1. Define a structure to hold the command name and arguments issued for the mini shell. This is what you use to capture the command issued before you pass it on to your shell for execution. Also declare a variable in_var to capture the command issued in the mini shell.
2. Initiate the command in a while loop.. So While(TRUE).. continue execution until an exit command is received. Within this loop you can use printf to stdout to display the shell prompt and follow it with a gets command to receive the mini shell commands.
3. If value gotten by gets is "exit" then return 0 for an exit.. If its something else you can go ahead and execute the same. You can use the strtok command to tokenize the input gotten by gets to separate out the command and arguments.
Thats it bud, I am trying to give you a general idea of how to write a mini shell without giving away the solution to your assignment.
Originally Posted by administrator