Thread: builtin command

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    4

    builtin command

    I am in the progress of creating a bash shell. I have created my own stand alone programs for ls, kill, ps etc etc. How do I incorporate them into my program? I've got two programs - one called <def.h> where all the definitions and globals are stored and the other one the main code, with the main function, getline function, parse function, execute function etc.

    The only bit i'm confused about is the builtin command - can anyone explain it to me? This is what I've found on the web site - and I don't understand it :-(
    builtin()
    {
    if (check("exit"))
    exit (0);
    else if (check("cd"))
    return do_cd();
    else if (check("history"))
    return do_history();
    else if (check("!"))
    return do_repeat_connand();
    else
    return 0;
    }

    The do_cd() function can then extract a directory name from the line[] array and use the chdir() system call to make the change. For the ! and history commands, you need to modify the getline() function so that lines entered at the keyboard are stored as they are entered. The history command can then list all the commands in the store and the command can copy the appropriate stored command back into the line[] array. do_repeat_command() can then return a zero from builtin() so that line[] will be parsed as normal.

    Do I need to specify the path of my program in the def.h??? How do I carry out my own script within the builtin command?!!!

    Thanks in advanced.
    J

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    87
    In the forkexec function you should see the following code.

    Code:
    execvp(ptr->av[0],ptr->av); 
    exit(1);
    If you use the execv function then u can execute ur own code, for example.

    Code:
    execv("cd.exe",ptr->av);
    exit(1);
    PuterPaul.co.uk - Portfolio site

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 10:43 AM
  2. problem with "touch" command in c program
    By Moony in forum C Programming
    Replies: 10
    Last Post: 08-01-2006, 09:56 AM
  3. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  4. Ping problem
    By bladerunner627 in forum C++ Programming
    Replies: 12
    Last Post: 02-02-2005, 12:54 PM
  5. exe files in -c- language
    By enjoy in forum C Programming
    Replies: 6
    Last Post: 05-18-2004, 04:36 PM