Find the answer to your Linux question:
Results 1 to 6 of 6
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Aug 2005
    Belgrade, Serbia

    How to write command-line-like applications


    Can anybody tell me where to find some kind of skeleton program for command-line-like applications? I want to create an application which gets its arguments from the command-line, but also has similar look like any standard bash command. For example:

    $ my_app --help
    $ my_app -r -m

    I saw a skelton for this kind of application, but I don't remeber where it was on the web.


  2. #2

  3. #3
    Super Moderator Roxoff's Avatar
    Join Date
    Aug 2005
    Nottingham, England
    Using C, this is a doddle, you dont even need a framework:

    int main (int argc, char ** argv)
       /*your code goes here*/
    Linux user #126863 - see

  4. $spacer_open
  5. #4
    Just Joined!
    Join Date
    Aug 2005
    Belgrade, Serbia
    This POPT library seems interesting and that is exactly the functionality I want. But, I have an embedded Linux system and I need something simplier. That's why I wanted some kind of C-code skeleton. I'm sure I saw it somewhere (written by a well-known Linux hacker, I think). I will see who POPT is applicable to my case.

  6. #5
    Linux Newbie
    Join Date
    May 2005
    Chennai,TamilNadu, India
    You can check out the getopt_long() function for this.

    You can have your own prompt and get the list of variable entered in the command line through the argc and argv
    then pass the argv array and argc values to the getopt_long function to parse ur command line options

    U can also have a look at the GNU readline library. It will help you a lot

    U can implement the doskey nature for ur commands, the tab feature in linux all using this library

    I have developed a CLI using all this.
    Its easy

  7. #6
    Good 'nix applications read from stdin (from a pipe) and accept
    arguments + options as well.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts