11

The following works:

git -C ~/dotfiles status

But this fails:

git status -C ~/dotfiles

Why is this?

31

This is because -C is a global option, and doesn't "belong" to the status action. This is a common pattern, resulting in synopses like the one below:

command [global options] action [action-specific options]

git --help lists Git's global options, and man git goes into more detail.

| improve this answer | |
  • 18
    It might be worth mentioning that every program defines its own option syntax, so this shouldn't be taken as a universal rule about options. Some of them can be moved around freely, some can only appear in certain places in the command line, and some can only show up in a specific order or a specific position. – David Z Aug 14 at 8:09
  • 3
    And these decisions are often made by the library a program uses to parse its arguments. For example, GNU ls (using GNU getopts) treats - in ls foo -l as the long output option. BSD ls (using a different library), on the other hand, treats it as a filename argument. – chepner Aug 14 at 17:24
  • 1
    @DavidZ well, kind of, at least for the standard UNIX tools it is standardized that options go before arguments in POSIX (with some exceptions). So, in general, it's likely that programs support at least that, although many GNU tools also allow options after arguments (as well as long opts, etc.) – ljrk Aug 14 at 23:53
  • @ljrk Yeah, but there are also things like git status -u which can't be flipped around to git -u status. And I figure a person who would ask this question might not be too familiar with command-line argument conventions in general, and so if they see something like du -s dir/ -h (GNU du of course) they might try to extract more meaning from that argument ordering than there really is. I just think it's easy to see one pattern or a few examples from one program and think all others work the same way, which is why I'd favor making the point that it really is up to the program. – David Z Aug 15 at 3:46
  • 1
    @DavidZ Yeah it is, this wasn't meant as a critique, just an addendum :) – ljrk Aug 15 at 8:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.