LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   command line options. How are they parsed when incompatible ones exist? (http://www.linuxquestions.org/questions/linux-general-1/command-line-options-how-are-they-parsed-when-incompatible-ones-exist-789590/)

kaz2100 02-16-2010 08:33 PM

command line options. How are they parsed when incompatible ones exist?
 
Hya,

Please excuse this extremely basic question.

Question is
When incompatible command line options exist, how are they parsed?

It looks like that
Code:

rm -f -i trash.*
behaves like
Code:

rm -i trash.*
So far, it looks like that options are parsed from left to right and right one overrides. But
Code:

ssh -v -v -v penguin@antarctica.the_earth
reads differently.

Is there any rule? (in POSIX, Linux, BSD, sparc, or unix?????)

Happy Penguins!

pixellany 02-16-2010 09:40 PM

I would simply try to think thru how I might try to write it....I visualize flags being set, with rules for what happens if there is a conflict. In principle, the parser would not care about the order of the options, as all the checking would be done just before execution.

And, you can;
--experiment
--read the source code

David the H. 02-16-2010 09:53 PM

I'm not a programming expert, but no doubt it's up to the individual program/programmer(s). Probably most programs use some form of getopt to parse the command string, in the order given, but then it's the programmer's job to decide what to do with the options that it finds. The easiest solution is usually to simply let later settings override earlier ones, but depending on what the options are supposed to do, that isn't always the smart thing.


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