Mike Kelly
Mike Kelly

Reputation: 183

The difference between arguments and options pertaining to the linux shell

I'm currently enrolled in an intro to Unix / Linux class and we came to a question that the instructor and I did not agree on.

cp -i file1 file2

Which is true about the preceding command?

I insisted that it was E. All of the above. The instructor has settled on D.

It seems clear that A, B, and D are all correct. The hang up was C and whether or not the -i flag was both an option and an argument.

My logic was that all options are arguments but not all arguments are options and since there are multiple true answers listed, then in multiple choice question tradition the answer is more than likely to be E all of the above.

I haven't been able to find the smoking gun on this issue and thought I would throw it to the masters.

Upvotes: 16

Views: 8917

Answers (5)

Jrican
Jrican

Reputation: 302

I know this is an old thread, but I want to add the following for anyone else that may stumble into a similar disagreement.

 $ ls -l junk
-rw-r--r-- 1 you     19 Sep 26 16:25 junk

"The strings that follow the program name on the command line, such as -l and junk in the example above, are called the program's arguments. Arguments are usually options or names of files to be used by the command."

Brian W. Kernighan & Rob Pike, "The UNIX Programming Environment"

Upvotes: 10

p_strand
p_strand

Reputation: 597

Hmmm... I personally like to distinguish between options and arguments however, you could technically say that options are arguments. I would say that you are correct but I think your instructor settled on D because he doesn't want you to get them confused. For example, the following is equivalent to the above command...:

 ARG1="-i" ; ARG2="file1" ; ARG3="file2" ; cp $ARG1 $ARG2 $ARG3

 ARG1="-i" ; ARG2="file1" ; ARG3="file2" ; cp $ARG2 $ARG1 $ARG3

 ARG1="-i" ; ARG2="file1" ; ARG3="file2" ; cp $ARG2 $ARG3 $ARG1

...whereas cp $ARG1 $ARG3 $ARG2 is not the same. I would say that options are a special type of arguments.

Upvotes: 0

Sammaye
Sammaye

Reputation: 43884

This is how I was taught, it is said in this case:

cp -i file1 file2

The right answer would be A B and D but not C.

Since -i is an option and file1 and file2 are arguments. Normally options are considered to change the behaviour of an application or command where as arguments do not.

I suppose it is up to semantics as to whether you consider -i an argument of the original application since it is a behaviour changing option (or argument) of cp but it is considered in English an option not a argument.

That's how I still define the difference and keep the difference between the two parts of a command.

As another command example, cronjobs. I often use PHP cronjobs and I normally have both options and arguments associated with the command. Options are always used (in my opinion) to define extra behaviour while arguments are designed to provide the app and it's behaviours with the data it requires to complete the operation.

Edit

I agree with @unwind this is splitting hairs and actually a lot of times comes down to scenario and opinion. It was quite bad of him to even mark on it really, he should of known this is a subjective question. Tests are completely unfair when filled with subjective questions.

Upvotes: 0

twalberg
twalberg

Reputation: 62389

I think the term "arguments" is used in different ways in different contexts, which is the root of the disagreement, it seems. In support of your stance though, note that the C runtime, upon which cp was most likely written, declares the program entry point as main(argc, argv) (types elided), which seems to indicate at least that those who designed the C architecture/library/etc. thought of options as a subset of arguments. Then of course options can have their own arguments (different context), etc....

Upvotes: 0

unwind
unwind

Reputation: 399863

The manual page here states:

Mandatory arguments to long options are mandatory for short options too.

This seems to imply that in the context of this particular question, at least, you're supposed to not consider options to be arguments. Otherwise it becomes very recursive and kind of pointless.

I think the instructor should accept your explanation though, this really is splitting hairs for most typical cases.

Upvotes: 2

Related Questions