16

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?

  • A. There is only one utility
  • B. There is one option
  • C. There are three arguments
  • D. file1 will be copied as file2 and the user will be warned before an overwrite occures
  • E. All of the above

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.

2
  • 1
    Your logic is correct. Doesn't your instructor have a correct answers sheet, or did he prepare that test?
    – lanzz
    Sep 19, 2012 at 14:37
  • 9
    This teaches an important meta-lesson: Many instructors are not qualified to teach what they are teaching. Keep that in mind in this and all classes. Sep 19, 2012 at 14:46

5 Answers 5

10

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"

3
  • 1
    Also IEEE Std 1003.1 2013 Edition, "12.1 Utility Argument Syntax" says that options are arguments.
    – Jrican
    Apr 8, 2015 at 21:38
  • This should actually be marked as the correct answer.
    – Slizzered
    Apr 8, 2015 at 21:51
  • I agree and have changed the answer
    – Mike Kelly
    Jun 17, 2015 at 20:28
2

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.

2
  • In my opinion, the question should not be considered in terms of the specific cp tool, but in terms of the general shell command line paradigm. You have a command line which specifies one command (cp, which could be an executable or an alias) and three arguments to that command; to the shell (and to execv), there is no distinction between option and non-option arguments. Besides, even if your reasoning is correct and disqualifies answer C, answers A, B and D would still be correct, and thus the question would not have a single correct answer and should be deemed invalid.
    – lanzz
    Sep 19, 2012 at 14:42
  • Thanks for all the feed back. I'm hoping this was an isolated case and that the rest of the semester won't be filled with these kind of scenarios. In the time since I posted the question a fellow class mate had tracked down the answer key to the book and it has all the above as the accepted answer. So I'm not sure what is going on with the instructor. Other than this she has been great. The answers post here make a lot of sense and thanks for the input
    – Mike Kelly
    Sep 19, 2012 at 17:30
0

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....

0

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.

0

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.

0

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.