-   Linux - General (
-   -   command line options. How are they parsed when incompatible ones exist? (

kaz2100 02-16-2010 09:33 PM

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

Please excuse this extremely basic question.

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

It looks like that

rm -f -i trash.*
behaves like

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

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 10: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;
--read the source code

David the H. 02-16-2010 10: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 09:09 AM.