Help creating Mini-shell??

This is a discussion on Help creating Mini-shell?? within the Linux Programming forums, part of the Platform Specific Boards category; I am trying to create a C-language mini UNIX shell that (for right now) enters my own shell and displays ...

  1. #1

    Help creating Mini-shell??

    I am trying to create a C-language mini UNIX shell that (for right now) enters my own shell and displays a prompt (i.e., READY:$> ), accepts a command from the command line, displays what the command is (The command you entered was: ) and any parameters that were passed along with it (i.e., -ls), and executes the command. I have SOME code, but I highly doubt it is correct. Can ANYONE help me?

  2. #2
    The Artful Lurker Deckard's Avatar
    Join Date
    Jan 2002
    I think your goal can be accomplished without much fuss.
    Please post what you've written and we can steer you in the right direction.
    Jason Deckard

  3. #3

    my code

    this is what i have so far....

    mars:$ cat shell2.c
    #include <stdio.h>
    #include <unistd.h>
    #include <stdlib.h>
    #include <iostream.h>

    cout<<"You have entered my 1814 shell"<<endl;
    bool exit=true;
    char *line[10];
    int n=0;
    while (!(exit))
    cout<<"The command you typed was: " <<line[0];

    if (gets(line)="exit")

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > char *line[10];
    You don't allocate any memory

    Start with this for now...
    char line[10][80];

    > bool exit=true;
    exit is a reserved function name, pick something else

    And it also needs to be set to false, if this is supposed to loop
    > while (!(exit))

    > execv(line[0],NULL);
    execv has more than this to it
    In particular, you need to break line[0] into individual words, and pass each word as a separate parameter to execv
    Also, there are several exec* functions, read about each one to decide which is best for you

    > if (gets(line)="exit")
    should be
    if ( strcmp( line[0], "exit" ) == 0 ) {

  5. #5
    Thank you...i appreciate it Salem. I used this code:

    #include <stdio.h>
    #include <unistd.h>
    #include <stdlib.h>
    #include <iostream.h>
    #include <string>
    #include <iomanip.h>
    cout<<"You have entered my 1814 shell"<<endl;
    string command;
    char *line[20];

    while (command !="exit")

    cout<<"The command you typed was: " <<command<<endl;
    if (command == "exit")
    return 0;

    }//end of while

    line[0] = "ls";
    line[1] = "-la"
    line[2] = NULL;

    execve("/bin/ls", line, NULL);

    if (command =="exit")
    return 0;
    }//end of main

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  2. Creating Shell based game..Few questions
    By Saintdog in forum Game Programming
    Replies: 1
    Last Post: 12-01-2004, 07:14 PM
  3. What shell is more powerful?
    By xddxogm3 in forum Tech Board
    Replies: 10
    Last Post: 07-24-2004, 10:47 PM
  4. Creating shell in C
    By LinMach in forum C Programming
    Replies: 8
    Last Post: 02-19-2003, 06:40 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21