LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Using Command Syntax to Create a List of Commands (https://www.linuxquestions.org/questions/linux-newbie-8/using-command-syntax-to-create-a-list-of-commands-4175638682/)

astrogeek 10-05-2018 03:08 PM

Quote:

Originally Posted by individual (Post 5911550)
I counted 57 options for ls. The combinations generated for that is a lot more than any user is going to want to read through.

Taking 57 as the number of available options, there are 395,010 possible ls commands which use different combinations of any 4 of those options. If you take that to all combinations of 5 options... 4,187,106. Try 7 options, 264,385,836. The list for all possible combinations would be the sum of the sub-combinations from 1 to 57... good luck with that!

The task as stated is simply not a reasonable thing to do. And not all combinations will be valid commands anyway, so the list would be useless without reference to the documentation, i.e. man pages of each base command.

As suggested by others, make a list of man pages and/or provide a synopsis.

individual 10-05-2018 04:43 PM

Quote:

Originally Posted by astrogeek (Post 5911555)
Taking 57 as the number of available options, there are 395,010 possible ls commands which use different combinations of any 4 of those options. If you take that to all combinations of 5 options... 4,187,106. Try 7 options, 264,385,836. The list for all possible combinations would be the sum of the sub-combinations from 1 to 57... good luck with that!

The task as stated is simply not a reasonable thing to do. And not all combinations will be valid commands anyway, so the list would be useless without reference to the documentation, i.e. man pages of each base command.

As suggested by others, make a list of man pages and/or provide a synopsis.

Thanks for posting some of the numbers. As far as I can tell, the most manageable would be taking 56 options at a time, which still leaves you with 57 combinations.

EDIT: I was going to post my calculation of combinations for the "cat" command in my previous post, but decided against it. There are 10 total options (not counting --help and --version), but 3 are essentially duplicates. You could take at most 7 at a time out of 10, which still leaves you with 120 possible combinations.

Kenhelm 10-06-2018 08:02 PM

The command syntax example in post #1 can be written as a brace expansion which will expand to a list of commands. The brace expansion in the perl bsd_glob version of glob is better for this than the one in bash because bash treats whitespace as a pattern separator.
http://perldoc.perl.org/functions/glob.html
http://perldoc.perl.org/File/Glob.html
Code:

# Globbing characters '*?[]~' and literal ',{}' need to be escaped with a backslash.
echo '{opt1 main-command <option-123>{, \[num <num>\]}{ avoid, allowable} <SomeVal>{, \[num1 <number_1>\], \[num2 <number_2>\]}{, \[num3 <number_3>\]}{, \[hide <hide>\]}}
{no opt1 main-command <option-123>{, \[num <num>\]}{,{ avoid, allowable} <SomeVal>{, \[num1 <number_1>\], \[num2 <number_2>\]}{, \[num3 <number_3>\]}{, \[hide <hide>\]}}}' |
perl -ne 'BEGIN{use File::Glob ":bsd_glob"} print sort glob'

opt1 main-command <option-123> [num <num>] allowable <SomeVal>
opt1 main-command <option-123> [num <num>] allowable <SomeVal> [hide <hide>]
opt1 main-command <option-123> [num <num>] allowable <SomeVal> [num1 <number_1>]
opt1 main-command <option-123> [num <num>] allowable <SomeVal> [num1 <number_1>] [hide <hide>]
opt1 main-command <option-123> [num <num>] allowable <SomeVal> [num1 <number_1>] [num3 <number_3>]
opt1 main-command <option-123> [num <num>] allowable <SomeVal> [num1 <number_1>] [num3 <number_3>] [hide <hide>]
opt1 main-command <option-123> [num <num>] allowable <SomeVal> [num2 <number_2>]
opt1 main-command <option-123> [num <num>] allowable <SomeVal> [num2 <number_2>] [hide <hide>]
opt1 main-command <option-123> [num <num>] allowable <SomeVal> [num2 <number_2>] [num3 <number_3>]
opt1 main-command <option-123> [num <num>] allowable <SomeVal> [num2 <number_2>] [num3 <number_3>] [hide <hide>]
opt1 main-command <option-123> [num <num>] allowable <SomeVal> [num3 <number_3>]
opt1 main-command <option-123> [num <num>] allowable <SomeVal> [num3 <number_3>] [hide <hide>]
opt1 main-command <option-123> [num <num>] avoid <SomeVal>
opt1 main-command <option-123> [num <num>] avoid <SomeVal> [hide <hide>]
opt1 main-command <option-123> [num <num>] avoid <SomeVal> [num1 <number_1>]
opt1 main-command <option-123> [num <num>] avoid <SomeVal> [num1 <number_1>] [hide <hide>]
opt1 main-command <option-123> [num <num>] avoid <SomeVal> [num1 <number_1>] [num3 <number_3>]
opt1 main-command <option-123> [num <num>] avoid <SomeVal> [num1 <number_1>] [num3 <number_3>] [hide <hide>]
opt1 main-command <option-123> [num <num>] avoid <SomeVal> [num2 <number_2>]
opt1 main-command <option-123> [num <num>] avoid <SomeVal> [num2 <number_2>] [hide <hide>]
opt1 main-command <option-123> [num <num>] avoid <SomeVal> [num2 <number_2>] [num3 <number_3>]
opt1 main-command <option-123> [num <num>] avoid <SomeVal> [num2 <number_2>] [num3 <number_3>] [hide <hide>]
opt1 main-command <option-123> [num <num>] avoid <SomeVal> [num3 <number_3>]
opt1 main-command <option-123> [num <num>] avoid <SomeVal> [num3 <number_3>] [hide <hide>]
opt1 main-command <option-123> allowable <SomeVal>
opt1 main-command <option-123> allowable <SomeVal> [hide <hide>]
opt1 main-command <option-123> allowable <SomeVal> [num1 <number_1>]
opt1 main-command <option-123> allowable <SomeVal> [num1 <number_1>] [hide <hide>]
opt1 main-command <option-123> allowable <SomeVal> [num1 <number_1>] [num3 <number_3>]
opt1 main-command <option-123> allowable <SomeVal> [num1 <number_1>] [num3 <number_3>] [hide <hide>]
opt1 main-command <option-123> allowable <SomeVal> [num2 <number_2>]
opt1 main-command <option-123> allowable <SomeVal> [num2 <number_2>] [hide <hide>]
opt1 main-command <option-123> allowable <SomeVal> [num2 <number_2>] [num3 <number_3>]
opt1 main-command <option-123> allowable <SomeVal> [num2 <number_2>] [num3 <number_3>] [hide <hide>]
opt1 main-command <option-123> allowable <SomeVal> [num3 <number_3>]
opt1 main-command <option-123> allowable <SomeVal> [num3 <number_3>] [hide <hide>]
opt1 main-command <option-123> avoid <SomeVal>
opt1 main-command <option-123> avoid <SomeVal> [hide <hide>]
opt1 main-command <option-123> avoid <SomeVal> [num1 <number_1>]
opt1 main-command <option-123> avoid <SomeVal> [num1 <number_1>] [hide <hide>]
opt1 main-command <option-123> avoid <SomeVal> [num1 <number_1>] [num3 <number_3>]
opt1 main-command <option-123> avoid <SomeVal> [num1 <number_1>] [num3 <number_3>] [hide <hide>]
opt1 main-command <option-123> avoid <SomeVal> [num2 <number_2>]
opt1 main-command <option-123> avoid <SomeVal> [num2 <number_2>] [hide <hide>]
opt1 main-command <option-123> avoid <SomeVal> [num2 <number_2>] [num3 <number_3>]
opt1 main-command <option-123> avoid <SomeVal> [num2 <number_2>] [num3 <number_3>] [hide <hide>]
opt1 main-command <option-123> avoid <SomeVal> [num3 <number_3>]
opt1 main-command <option-123> avoid <SomeVal> [num3 <number_3>] [hide <hide>]
no opt1 main-command <option-123>
no opt1 main-command <option-123> [num <num>]
no opt1 main-command <option-123> [num <num>] allowable <SomeVal>
no opt1 main-command <option-123> [num <num>] allowable <SomeVal> [hide <hide>]
no opt1 main-command <option-123> [num <num>] allowable <SomeVal> [num1 <number_1>]
no opt1 main-command <option-123> [num <num>] allowable <SomeVal> [num1 <number_1>] [hide <hide>]
no opt1 main-command <option-123> [num <num>] allowable <SomeVal> [num1 <number_1>] [num3 <number_3>]
no opt1 main-command <option-123> [num <num>] allowable <SomeVal> [num1 <number_1>] [num3 <number_3>] [hide <hide>]
no opt1 main-command <option-123> [num <num>] allowable <SomeVal> [num2 <number_2>]
no opt1 main-command <option-123> [num <num>] allowable <SomeVal> [num2 <number_2>] [hide <hide>]
no opt1 main-command <option-123> [num <num>] allowable <SomeVal> [num2 <number_2>] [num3 <number_3>]
no opt1 main-command <option-123> [num <num>] allowable <SomeVal> [num2 <number_2>] [num3 <number_3>] [hide <hide>]
no opt1 main-command <option-123> [num <num>] allowable <SomeVal> [num3 <number_3>]
no opt1 main-command <option-123> [num <num>] allowable <SomeVal> [num3 <number_3>] [hide <hide>]
no opt1 main-command <option-123> [num <num>] avoid <SomeVal>
no opt1 main-command <option-123> [num <num>] avoid <SomeVal> [hide <hide>]
no opt1 main-command <option-123> [num <num>] avoid <SomeVal> [num1 <number_1>]
no opt1 main-command <option-123> [num <num>] avoid <SomeVal> [num1 <number_1>] [hide <hide>]
no opt1 main-command <option-123> [num <num>] avoid <SomeVal> [num1 <number_1>] [num3 <number_3>]
no opt1 main-command <option-123> [num <num>] avoid <SomeVal> [num1 <number_1>] [num3 <number_3>] [hide <hide>]
no opt1 main-command <option-123> [num <num>] avoid <SomeVal> [num2 <number_2>]
no opt1 main-command <option-123> [num <num>] avoid <SomeVal> [num2 <number_2>] [hide <hide>]
no opt1 main-command <option-123> [num <num>] avoid <SomeVal> [num2 <number_2>] [num3 <number_3>]
no opt1 main-command <option-123> [num <num>] avoid <SomeVal> [num2 <number_2>] [num3 <number_3>] [hide <hide>]
no opt1 main-command <option-123> [num <num>] avoid <SomeVal> [num3 <number_3>]
no opt1 main-command <option-123> [num <num>] avoid <SomeVal> [num3 <number_3>] [hide <hide>]
no opt1 main-command <option-123> allowable <SomeVal>
no opt1 main-command <option-123> allowable <SomeVal> [hide <hide>]
no opt1 main-command <option-123> allowable <SomeVal> [num1 <number_1>]
no opt1 main-command <option-123> allowable <SomeVal> [num1 <number_1>] [hide <hide>]
no opt1 main-command <option-123> allowable <SomeVal> [num1 <number_1>] [num3 <number_3>]
no opt1 main-command <option-123> allowable <SomeVal> [num1 <number_1>] [num3 <number_3>] [hide <hide>]
no opt1 main-command <option-123> allowable <SomeVal> [num2 <number_2>]
no opt1 main-command <option-123> allowable <SomeVal> [num2 <number_2>] [hide <hide>]
no opt1 main-command <option-123> allowable <SomeVal> [num2 <number_2>] [num3 <number_3>]
no opt1 main-command <option-123> allowable <SomeVal> [num2 <number_2>] [num3 <number_3>] [hide <hide>]
no opt1 main-command <option-123> allowable <SomeVal> [num3 <number_3>]
no opt1 main-command <option-123> allowable <SomeVal> [num3 <number_3>] [hide <hide>]
no opt1 main-command <option-123> avoid <SomeVal>
no opt1 main-command <option-123> avoid <SomeVal> [hide <hide>]
no opt1 main-command <option-123> avoid <SomeVal> [num1 <number_1>]
no opt1 main-command <option-123> avoid <SomeVal> [num1 <number_1>] [hide <hide>]
no opt1 main-command <option-123> avoid <SomeVal> [num1 <number_1>] [num3 <number_3>]
no opt1 main-command <option-123> avoid <SomeVal> [num1 <number_1>] [num3 <number_3>] [hide <hide>]
no opt1 main-command <option-123> avoid <SomeVal> [num2 <number_2>]
no opt1 main-command <option-123> avoid <SomeVal> [num2 <number_2>] [hide <hide>]
no opt1 main-command <option-123> avoid <SomeVal> [num2 <number_2>] [num3 <number_3>]
no opt1 main-command <option-123> avoid <SomeVal> [num2 <number_2>] [num3 <number_3>] [hide <hide>]
no opt1 main-command <option-123> avoid <SomeVal> [num3 <number_3>]
no opt1 main-command <option-123> avoid <SomeVal> [num3 <number_3>] [hide <hide>]


Habitual 10-08-2018 03:40 PM

Maybe use someone else's hard work and Not re-invent the wheel.
https://ss64.com/bash/
https://www.commandlinefu.com/commands/browse

and if-n you're bored,
https://www.commandlinefu.com/comman...-using-the-api

I've read that shit 1000 times.
I'm with astrogeek on this one.
And they are already ubiquitously "documented" IMO. ;)

Code:

man <cmd>
apropos <cmd>
info <cmd>
whatis <cmd>

and short help
Code:

cmd -h
and long
Code:

cmd --help

All cmds on the system:
Code:

compgen -c | sort -u > commands
Now parse commands file from that. 1\2 way there!


Documented in /usr/share/man/...

Hope that helps.

SomeDumbGuy 10-08-2018 11:32 PM

Quote:

Originally Posted by ondoho (Post 5911464)
^ i see.
but:
each command belong to a software package and these packages most likely already contain documentation. so that's where you look first.
most likely there's a man page for each command.
or there's something in /usr/share/doc/command_package.
doc stands for documentation.
failing that, the option you're looking for is one of:
Code:

command -h
command --help
man command
# and very rarely
command -?

but still:
i fail to understand why you have to re-create this documentation when it's already there. i think you're just missing something here.

These aren't Linux commands and there isn't any documentation yet (I'm working on it).


All times are GMT -5. The time now is 02:19 AM.