Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The difference between arguments and options pertaining to the linux shell

Tags:

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?

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

like image 558
Mike Kelly Avatar asked Sep 19 '12 14:09

Mike Kelly


People also ask

What is the difference between argument and option in Linux?

Argument 0 is (normally) the command name, argument 1, the first element following the command, and so on. These arguments are sometimes called positional parameters. An option is a documented1 type of argument modifying the behavior of a command, e.g. -l commonly means "long", -v verbose.

What is the difference between arguments and options?

options help define how a command should behave. Some may be optional. arguments tell commands what object to operate on.

What does arguments mean in Linux?

An argument, also called command line argument, can be defined as input given to a command line to process that input with the help of given command. Argument can be in the form of a file or directory. Arguments are entered in the terminal or console after entering command. They can be set as a path.

What is argument in shell?

The Unix shell is used to run commands, and it allows users to pass run time arguments to these commands. These arguments, also known as command line parameters, that allows the users to either control the flow of the command or to specify the input data for the command.


2 Answers

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"

like image 150
Jrican Avatar answered Oct 08 '22 00:10

Jrican


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.

like image 32
unwind Avatar answered Oct 07 '22 23:10

unwind