Find the answer to your Linux question:
Results 1 to 6 of 6
Hi! 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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Aug 2005
    Location
    Belgrade, Serbia
    Posts
    8

    How to write command-line-like applications


    Hi!

    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
    etc.

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

    Thanks,
    Sasa

  2. #2
    Just Joined!
    Join Date
    Oct 2005
    Location
    India
    Posts
    2

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

    Code:
    int main (int argc, char ** argv)
    {
       /*your code goes here*/
    }
    Linux user #126863 - see http://linuxcounter.net/

  4. #4
    Just Joined!
    Join Date
    Aug 2005
    Location
    Belgrade, Serbia
    Posts
    8
    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.

  5. #5
    Linux Newbie
    Join Date
    May 2005
    Location
    Chennai,TamilNadu, India
    Posts
    141
    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

  6. #6
    Linux Newbie
    Join Date
    Oct 2004
    Posts
    158
    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
  •