Thread: basic linux shell programming

  1. #1
    Registered User
    Join Date
    Jan 2015
    Posts
    12

    Question basic linux shell programming

    here is the question:

    Your task is to write a simple Unix command-line shell (like bash). Obviously your shell will not be as featureful as bash is. Your shell will be written in C.
    Your shell should consist of a loop which:

    • Reads in a line of text from the user (e.g., via fgets). You may assume a maximum line length of 100 characters
    • Parses that line of text into an array of words
    • Using the fork(), execvp() and waitpid() system calls, launches the requested program and waits until the program has finished

    In addition to running external programs, your shell must also support 2 builtin commands (commands which are handled by NOT fork()ing and execvp()ing). Those two builtin commands are:

    • exit. If the user types in "exit" as a command, your shell should exit (i.e., end the loop)
    • cd. If the user types in "cd" followed by another word, your shell should execute the chdir() system call directly. The chdir() system call has not been discussed in class, but you should find sufficient documentation on chdir() by typing in "man chdir" at a Linux command-line or by typing "man chdir" into Google

    To determine whether the user has typed in a bulitin command or typed in a command that should be completed by an external program (via fork() and execvp()), use the strcmp function in standard C. The strcmp function will return to you a value of 0 if two strings have the same value, which can be used to determine if the user typed in "exit" or "cd".

  2. #2
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    That sounds like a great assignment; I'm sure you'll enjoy it and learn a lot from it. I highly recommend you read the following links to help you get started:
    Announcements - Linux Programming
    Announcements - General Programming Boards
    How To Ask Questions The Smart Way
    A development process

  3. #3
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Ugh...cross-posted...on the same site: basic linux shell programming

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Basic Linus Shell
    By Josh_Dude83 in forum C Programming
    Replies: 11
    Last Post: 09-19-2010, 07:43 PM
  2. basic shell command execution
    By Opel_Corsa in forum Linux Programming
    Replies: 4
    Last Post: 10-20-2006, 08:37 AM
  3. shell script basic question
    By PedroTuga in forum Linux Programming
    Replies: 1
    Last Post: 09-09-2006, 03:24 AM
  4. A basic shell question
    By AngKar in forum C# Programming
    Replies: 1
    Last Post: 06-20-2006, 05:18 PM
  5. Basic Shell Script-Very Frustrating
    By kwigibo in forum Linux Programming
    Replies: 8
    Last Post: 05-19-2002, 02:43 AM

Tags for this Thread