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 ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: Mini Shell - How to create in C

  1. 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

    Test Cases

    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

  2. Post 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.


    Quote Originally Posted by administrator View Post
    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

    Test Cases

    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

+ Reply to Thread