12

I am trying to understand info who but completly fail at the term "non-option argument". Can someone please explain this term to me in simple words or an example?

UPDATE: from info who :

If given no non-option arguments, who prints the following information for each user currently logged on: login name, terminal line, login time, and remote hostname or X display.

If given one non-option argument, who uses that instead of a default system-maintained file (often /var/run/utmp or /etc/utmp) as the name of the file containing the record of users logged on. /var/log/wtmp is commonly given as an argument to who to look at who has previously logged on.

If given two non-option arguments, who prints only the entry for the user running it (determined from its standard input), preceded by the hostname. Traditionally, the two arguments given are am i, as in who am i.

I [thought to] know the difference between an argument and an option, but this [again] nixes a lot.

9
  • 3
    If I hadn't witnessed the info who I never would've believed that someone would use the term "no non-option arguments". That's pretty lame.
    – slm
    Oct 19, 2013 at 1:47
  • 2
    "time spent figuring out stuff like that" vs. "actually learning how to use the gained knowledge" is about 7:3 for me. Which leads to the seriously meant question: What am I doing wrong?!
    – erch
    Oct 19, 2013 at 1:53
  • 2
    I think that's pretty normal, especially when you're starting out. After you build up a large enough base knowledge do you start to see the repeating patterns around Unix and things start to become easier. How long you been at it? Bah you're 20 years old? You're doing well, keep at it, it get's easier!
    – slm
    Oct 19, 2013 at 2:13
  • 1
    The hardest part is acquiring the knowledge, it get's easier too, but ppl have been building these systems for 40+ years so don't expect things to come instantly, you have to want it.
    – slm
    Oct 19, 2013 at 2:15
  • 3
    GNU info pages have probably done more damage to being able to learn UNIX. They are harder to use and navigate than man pages, and since they exist, most folks consider a real man page to be optional. So you end up with terrible documentation. This is part of what has made me love the BSDs, particular OpenBSD. The man pages are almost always good and useful. And if they are not, the developers consider it a bug.
    – kurtm
    Oct 20, 2013 at 5:59

5 Answers 5

12

The terminology is not completely fixed, so different documentation uses different terms, or worse, the same terms with different meanings. The terminology in the man page you're reading is a common one. It is the one used in the POSIX standard. In a nutshell, each word after the command is an argument, and the arguments that start with - are options.

Argument

In the shell command language, a parameter passed to a utility as the equivalent of a single string in the argv array created by one of the exec functions. An argument is one of the options, option-arguments, or operands following the command name.

Operand

An argument to a command that is generally used as an object supplying information to a utility necessary to complete its processing. Operands generally follow the options in a command line.

Option

An argument to a command that is generally used to specify changes in the utility's default behavior.

“Utility” is what is generally called “command” (the standard uses the word utility to avoid ambiguity with the meaning of “command” that includes the arguments or even compound shell commands).

Most commands follow the standard utility argument syntax, where options start with a - (dash a.k.a. minus). So an option is something like -a (short option, follows the POSIX guidelines) or --all (long option, an extension from GNU). A non-option argument is an argument that doesn't begin with -, or that consists solely of - (which who treats as a literal file name but many commands treat as meaning either standard input or standard output).

In addition, some options themselves have an argument. This argument can be passed in several ways:

  • For a single-letter option, in the same argument to the utility: foo -obar: bar is the argument to the single-letter option -o.
  • In the GNU long argument syntax, in the same argument, separated by an equal sign: foo --option=bar.
  • In a separate argument: foo -o bar or foo --option bar. If the option -o (or --option) takes an argument, then bar is the argument of the option -o (or --option). If -o (or --option) does not take an argument then bar is an operand.

Here's a longer example:

tail -n 3 myfile

-n is an option, 3 is an argument to the option -n, and myfile is an operand.

Terminology differs, so you may find documents that use argument in the sense where POSIX uses operand. But “non-option argument” is more common than either term for this meaning.

0
5

The thing is, options (or switches or flags, whatever you like to call them) count as arguments too. In fact, anything you supply after the command name itself makes up the command's arguments (except for constructs used by the shell like redirection, for instance).

Your program/script receives everything together as arguments and needs to separate the option arguments (arguments that are options) from other... you guessed it!... non-option arguments.

So what the info page is saying is that if who receives an argument that is not an option, it will consider that as an alternative to the default file it consults for log in information.

4
  • 3
    If I hadn't witnessed the info who I never would've believed that someone would use the term "no non-option arguments". That's pretty lame.
    – slm
    Oct 19, 2013 at 1:46
  • @slm I don't know about that. Still technically correct, though...
    – Joseph R.
    Oct 19, 2013 at 9:00
  • Do I get this right: everything not an option is a non-argument?!** And also: option = switch = flag = argument?
    – erch
    Oct 19, 2013 at 17:44
  • @chirp Everything not an option is still an argument but it's a non-option argument. Just to add to the confusion: some options can have arguments :) Oh and option=switch=flag loosely holds, yes.
    – Joseph R.
    Oct 19, 2013 at 18:45
1

I still think the phrasing is poor on this and would try not to get hung up. What they're trying to say is that in the prototype statement they included like this:

 `who' [OPTION] [FILE] [am i]

So when they say "If given no non-option arguments" they're referring to [FILE] and [am i].

Following that logic when they say "If given one non-option argument", i.e. [FILE], then you're overriding the [FILE] location, /var/run/utmp.

Lastly for this comment, "If given two non-option arguments", i.e. [am i] then you're asking for info about the user that just ran the command:

$ who am i
saml     pts/5        2013-10-18 16:29 (:0.0)

-or-

$ who mom likes
saml     pts/5        2013-10-18 16:29 (:0.0)

The description is apt, but they've definitely confused it by using the term "no non-option arguments".

In the authors mind these are the options:

  -a, --all         same as -b -d --login -p -r -t -T -u
  -b, --boot        time of last system boot
  -d, --dead        print dead processes
  -H, --heading     print line of column headings
  -l, --login       print system login processes
      --lookup      attempt to canonicalize hostnames via DNS

  ....

And [FILE] and [am i] and [mom likes] are the non-options. But these are ALL options, so the difference is limited to just this tool!

2
  • 1
    “Non-option argument” is perfectly standard terminology (both literally and colloquially). See my answer. Oct 20, 2013 at 0:35
  • 1
    @Gilles - I figured you or Stephane would explain this one, I still think the terminology is poor. Defining things this way is like using negative language when defining a conditional in an if statement. if ($notStatus != option). I understand what it means but it's at best confusing. Good answer BTW, per usual 8-)
    – slm
    Oct 20, 2013 at 0:50
0

In the man page for adduser, non-option argument is mentioned three times.

One part of the man page is very interesting:

If called with two non-option arguments, adduser will add an existing user to an existing group.

The synopsis of adduser command looks like:

adduser [options] user group

Here, user and group are non-option arguments.

To add an user we have to give username. For example:

adduser User1

To add an existing user to an existing group, we have to use:

adduser User1 Group1

Some command take some arguments without any options. For example, we are not saying adduser --user User1. These are non-option arguments.

Let's make it more clear. Let us check the synopsis of cat command.

SYNOPSIS
       cat [OPTION]... [FILE]...

Here, FILE is the non-option argument.

-1

Usually a non-option argument

  • follows a command in a command-line string
  • does not start with - or --
  • does not follow an option which requires an argument
  • (if part of the command string) is often the only required argument

Example:

           option    non-option arg
command  --verbose   /dir/file.txt

or:

          option    argument of -o    non-option arg
command     -o          /dst          /src/file.txt

Is it easy to distinguish between an argument and a non-option? No. It depends on the specific command how it parses the options, so reading its documentation is required:

            option     argument of -a
command_A    -a        /dir/file.txt

            option     non-option arg
command_B    -a        /dir/file.txt

Note: In rare cases non-options start with a -:

      non-option arg   non-option arg
set         --              -a
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .