LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-22-2011, 08:25 AM   #1
backdoor
LQ Newbie
 
Registered: Sep 2011
Posts: 4

Rep: Reputation: Disabled
Generating list of options of a command using script


Hi,

I am looking to write a script which could generate list of all the options available for a command. Problems i am facing are
1) I have to generate the options list for all available commands in man1 to start. Ex for ls command (I want to generate -l, -d, -b, -c, etc etc)
2) Formats of the man pages vary for different commands. (Even the roff formats are different).
3) On later stages I will have to extract arguments in system calls, function calls etc.

is there a easy way to accomplish this.
Thank you !!
 
Old 09-22-2011, 10:20 AM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian + kde 4 / 5
Posts: 6,842

Rep: Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004
No, I can see no easy way to do this. You'd need some uniform way to locate the data you need, and as you said yourself, program documentation isn't uniform. Neither are programs, for that matter. Just try looking at all the options mplayer has, for example, and ps can accept options in three different formats.

With a bit of work you might be able to get something that works in the majority of cases, but there will likely be many exceptions that can't be easily handled.

It might help a bit if you told us why you want to do this--a bit of context. Perhaps there's some other way of satisfying your real goal.

Last edited by David the H.; 09-22-2011 at 10:22 AM.
 
Old 09-22-2011, 08:21 PM   #3
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 234Reputation: 234Reputation: 234
Moderation
1st, this doesn't belong in Kernel & I need some feedback from about your goals in order to decide where to move it.
Are you focussed on one particular Linux distro or version. of *nix, or is this primarily a more general scripting question?


Attempt to actually help
From 1) above I see you know where to go to find them (on my system /usr/share/man/man1 containing 1,446 files & soft links.)

2) tells me you have a good idea of the contents, & the problems their lack of uniformity causes.

I do have one off-the-wall, but possibly good, suggestion: Use the KDE "man:" kioslave, possibly working together w/ wget or cURL, to do the basic work for you.

The man kioslave allows you to put "man:<command>" into Konqueror's location bar & get the man page displayed in HTML. (It even turns the "SEE ALSO" entries into clickable links.)

Both wget & cURL can be called from a script, but I don't know if there is is any URL on localhost for them to reference.

I also have never played w/ trying to operate Konqueror under the control of a script, so I have no idea how easy, or even possible that would be.

I do know that Konqueror's HTML display of man pages looks pretty uniform to me. I suspect that if you produce & save the .html files, you can probably grep, sed, awk the info. you need out of them. As a last resort, you could even use perl.

It all depends on the ease of automatically producing the .html man pages -- I doubt you want to individually "Save As" them.
 
Old 09-23-2011, 03:02 AM   #4
backdoor
LQ Newbie
 
Registered: Sep 2011
Posts: 4

Original Poster
Rep: Reputation: Disabled
Hi all,

Thanks for the reply..

I am trying to document list of arguments which are different in two different Unix versions (That is the main objective). I would even have to do that for system calls arguments and function calls. Accuracy is very crucial in my case and therefore some formating differences can cause lot of problem.

Converting things to html might or might not work because the basic files of the documents itself are pretty varying.
I am little dissapointed that no one has attempted this before ..
Anyways thanks for the help. I will try the solutions and let you guys know. !!

Thhnkas again
 
Old 09-23-2011, 09:10 AM   #5
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 234Reputation: 234Reputation: 234
Quote:
Originally Posted by backdoor View Post
Thanks for the reply..
You're welcome.

Quote:
Originally Posted by backdoor View Post
I am trying to document list of arguments which are different in two different Unix versions (That is the main objective). I would even have to do that for system calls arguments and function calls. Accuracy is very crucial in my case and therefore some formating differences can cause lot of problem.
Which 2 Unix versions? NB: The answer to this is crucial in deciding where to move this.

Quote:
Originally Posted by backdoor View Post
Converting things to html might or might not work because the basic files of the documents itself are pretty varying.
Do you have KDE & Konqueror available for both target Unices? Even if you do, the HTML conversion idea may not help; still, I have to ask.

Quote:
Originally Posted by backdoor View Post
I am little dissapointed that no one has attempted this before ..
That is probably due to the nature of Free Software. Implicit in the license is freedom to do what you want, & conversely to not do what you don't want to do.
Are you familiar w/ The Cathedral and the Bazaar? From its WikipediaŽ article:
Quote:
Guidelines for creating good open source software
There are 19 guidelines for creating good open source software listed in his essay:
1. Every good work of software starts by scratching a developer's personal itch.
It seems you are the 1st one (that you know of) to have this itch.

Quote:
Originally Posted by backdoor View Post
I will try the solutions and let you guys know. !!
Please do, posting your results adds to the LQ archive & will help others in the future.

Quote:
Originally Posted by backdoor View Post
Thhnkas again
You're welcome again.
 
Old 09-24-2011, 07:24 AM   #6
backdoor
LQ Newbie
 
Registered: Sep 2011
Posts: 4

Original Poster
Rep: Reputation: Disabled
I am trying to document stuff to make ppl using solaris to move to linux

Thanks for the comments and help !!
 
Old 09-26-2011, 07:39 AM   #7
backdoor
LQ Newbie
 
Registered: Sep 2011
Posts: 4

Original Poster
Rep: Reputation: Disabled
Hi again..

I am trying to convert the file into html and then finding the right tags. Though again its not exhaustive but better than other ways.

Right now I am trying to figure out if there is a way to check whether a given option exists or not without running the command.

For example when I do "ls -wrong_argument" it gives an error message. But if the command is right it obv runs it. I dont want to run it, just check if the argument is there or not.

Thanks again.
 
Old 10-02-2011, 06:04 AM   #8
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian + kde 4 / 5
Posts: 6,842

Rep: Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004
I don't know if it will help you, but I just stumbled across this project. It looks like it might help you to get man pages into a more parseable format.

http://www.catb.org/~esr/doclifter/
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Partial list with ls-l in bash script run in cron but full list run from command line redgshost Linux - General 29 01-16-2011 01:14 PM
Shell script - Pass command options with equal sign fabdog Linux - Newbie 5 02-13-2009 07:32 AM
bash: generating a string containing options and using with kdialog arizonagroovejet Programming 1 06-12-2008 03:12 PM
Generating a list of installed packages KaYoS Slackware 4 05-30-2006 03:40 PM
Solaris 10 Upgrade - Generating Backup List btmiller Solaris / OpenSolaris 1 02-21-2005 02:36 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:05 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration