Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

In bash, I am not sure if my observation is correct. For most commands, option-like arguments, i.e. arguments that begin with --abc or -a, can be anywhere in the list of arguments to the command, while other arguments have some fixed position in the list of arguments.

I was wondering if there are some written/unwritten rules about this? Thanks!

share|improve this question
    
Anyone recalls a command where argument order matters? Because I don't. –  alex Jul 21 '11 at 17:09
1  
I can - piping stuff into grep xD oh, and rsync, and ln –  Thomas W. Jul 21 '11 at 17:57
    
@alex: I can think of dozens. cp, mv, rsync, ssh, watch, make, find ... the list goes on. –  Caleb Jul 21 '11 at 20:25
    
Okay, okay, what if restrict that to options, not arguments: i.e. -a, -b, -c, etc. –  alex Jul 21 '11 at 20:42

3 Answers 3

up vote 8 down vote accepted

In short - it depends on the program. What bash does is it sends the arguments to the program's main function, which from then on decides what to do with them. Some programs don't care about argument order, some take it into account.

share|improve this answer
1  
Although usually if the program takes -aa arguments, it's a strong indication that it's using getopt() or similar, which doesn't care about arg order –  Shadur Jul 21 '11 at 14:40
2  
@Shadur getopt preserves argument order; it's up to the application whether the argument order matters. –  Gilles Jul 21 '11 at 15:28

man commandName Will tell you if it matters for the command you are trying to use, generally, some thing which starts with - are options which modify the behavior of the command, and the others are arguments (you can take it as input) for the command.

share|improve this answer

Here's a notable example where a program's arguments' order matters: Compare output from:

find . -type f -atime 0 -daystart

with:

find . -type f -daystart -atime 0

(On a drive that stores a file's atime, I need to add these days). There are many webpages devoted to getting you started with find(1), but almost none mention the fact that find, for one, is VERY particular about the order of its arguments.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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