Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Building a simple Shell for linux

  1. May 15, 2007 #1

    I'm trying to build a shell for Linux, programming it in c currently. I need to be able to read a command like 'copy2flash' so that it'll copy itself to another flash memory, but right now I need the case instruction to be able to recognize the command and print something like "copying to device" I'm not sure how to do this with an array of chars?

    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <strings.h>
    #include <string.h>

    #define MAX 80 /* 80 chars per line, per command, should be enough. */

    int main(int argc, char *argv[], char *envp[])
    /* Inicializa a c y tmp. */
    char string [MAX];
    char c = '\0';
    char tmp = '\0';
    printf("Welcome to MySHELL, use 'copy2flash' to copy flash memory\n");
    printf("to another flash memory to another system\n");
    printf("[MySHELL] ");
    while(c != EOF) {
    c = getchar();
    switch(c) {
    case '\n': /* parse y ejecute. */
    printf("[MySHELL] ");
    /**** case 'copy2flash': parse y ejecute.
    printf("Copying to another flash...");
    bzero(&tmp, 1);
    break; */
    default: strncat(&tmp, &c, 1);
    /* some processing before terminating. */
    return 0;
  2. jcsd
  3. May 15, 2007 #2


    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    Use the string comparison methods like strcmp().

    - Warren
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?

Similar Discussions: Building a simple Shell for linux
  1. Fortran in Linux (Replies: 3)

  2. Learn linux (Replies: 6)