21

At the command line I often use "simple" commands like

mv foo/bar baz/bar

but I don't know what to call all the parts of this:

┌1┐ ┌──2───┐
git checkout master
│   └──────3──────┘
└───────4─────────┘

I (think I) know that 1 is a command and 2's an argument, and I'd probably call 3 an argument list (is that correct?).

However, I don't know what to call 4.

How are more complex "commands" labelled?

find transcripts/?.? -name '*.txt' | parallel -- sh -c 'echo $1 $2' {} {/}

I'd appreciate an answer that breaks down what to call 1,2,3,4 and what to call each part of e.g. this "command" above.

It would be great to learn also about other things that are unique/surprising that I haven't included here.

  • 1
    Have you looked at the man pages for git and find, in particular the synopsis section? – fpmurphy Jan 14 '18 at 1:55
  • 4
    Have you looked at the man pages for git and find So the question seems nothing to do with git or find rather general terminology for linux. – Att Righ Jan 14 '18 at 2:02
  • According to the bash man page in A | B, A | B is a pipeline, A and B are commands (it's unfortunate that this has the same name as just the first world in a command). I might call the first argument an executable but I can't find a source that agrees with me. – Att Righ Jan 14 '18 at 2:24
  • 4
    In the context of git checkout ..., checkout is a subcommand, and in the context of sh -c ..., -c is an option. – wjandrea Jan 14 '18 at 4:15
  • @JoL thanks for pointing that out. You guessed right, I've edited that. It's because I re-wrote that section some 4 times as I tried to do it properly – theonlygusti Jan 14 '18 at 10:15
33

The common names for each part is as follows:

┌1┐ ┌──2───┐
git checkout master
│   └──────3──────┘
└───────4─────────┘
  1. Command name (first word or token of command line that is not a redirection or variable assignment and after aliases have been expanded).

  2. Token, word, or argument to the command. From man bash:

    word: A sequence of characters considered as a single unit by the shell. Also known as a token.

  3. Generally: Arguments

  4. Command line.

The concatenation of two simple commands with a | is a pipe sequence or pipeline:

┌─1┐ ┌──────2──────┐ ┌─2─┐ ┌──2──┐   ┌──1───┐ ┌2┐┌2┐┌2┐┌────2─────┐ ┌2┐ ┌2┐
find transcripts/?.? -name '*.txt' | parallel -- sh -c 'echo $1 $2'  {} {/}
│    └────────────3──────────────┘            └────────────3──────────────┘
└───────────────────────────────────4─────────────────────────────────────┘

Mind that there are redirection and variable assignments also:

┌──5──┐ ┌1┐ ┌─2─┐ ┌─2─┐   ┌───6──┐ ┌1┐ ┌─5─┐
<infile tee file1 file2 | LC_ALL=C cat >file
└─────────7───────────┘   └───────7────────┘
└─────────────────────4────────────────────┘

Where (beside the numbers from above):

  1. redirection.
  2. Variable assignment.
  3. Simple command.

This is not an exaustive list of all the element a command line could have. Such a list is too complex for this short answer.

  • 2
    In POSIX terminology, what you call pipe is a pipe sequence or pipeline (though a pipeline can have an optional leading ! to negate its status). pipe would rather refer to the IPC mechanism used by most shells to implement pipelines (pipelines don't have to use pipes, ksh93 uses socketpairs instead on some systems for instance). Some shells have more keywords like time, noglob that can be used instead or in addition to ! here. – Stéphane Chazelas Jan 14 '18 at 9:53
  • 1
    IMHO, these things are called arguments - nothing else so I think the word token in this context means "atomic unit of bash's grammar". Here the term token only exists in the context of shell command line, not in the context of the program executes. It would be a bit weird to say "these are the programs tokens" but perhaps less strange to say "the second token in the command line is $test". A distinction comes up in cat $file, here I would say $file is a token, but the value of file is the argument. – Att Righ Jan 14 '18 at 20:44
  • 1
    @PeterCordes You are correct, <<<"…" is a redirection, not an argument. Though it is still a token of the line. Sorry for the confusion. – Isaac Jan 14 '18 at 21:52
  • 1
    @TOOGAM Those are exactly opposite to the standard definitions. The things the caller provides are arguments; cf. “formal parameter”, or this SO question. – Michael Homer Jan 15 '18 at 5:30
  • 1
    @TOOGAM "What I see are parameters". Hmm I think you are right. According the POSIX spec: "The shell executes a function (see Function Definition Command), built-in (see Special Built-In Utilities), executable file, or script, giving the names of the arguments as positional parameters numbered 1 to n, and the name of the command (or in the case of a function within a script, the name of the script) as the positional parameter numbered 0 (see Command Search and Execution)." and I had been wrong all these years... Although in my defense it is called argv – Att Righ Jan 15 '18 at 13:03
15

@isaac's answer above seems good.

I want to extend this with some sources.

I guess the POSIX standard might in some sense be considered canonical. Other sources might be man bash and man proc.

┌1┐ ┌──2───┐
git checkout master
│   └──────3──────┘
└───────4─────────┘

POSIX suggests that:

  1. Is the command name (rather than the command, though even this document uses command in places)
  2. Argument
  3. Arguments
  4. Command (though man proc uses the command line)

It also has terminology for many more complicated commands.

I think command is pretty ambiguous so perhaps the term command name and command line are good for clarity.j

  • What's proc? I've never heard of that. – theonlygusti Jan 14 '18 at 10:18
  • @theonlygusti man7.org/linux/man-pages/man5/proc.5.html – Moira Jan 14 '18 at 10:42
  • 5
    +1 I like this answer best. (In this specific context, 2 is a subcommand, but generally yes, an argument). – kubanczyk Jan 14 '18 at 14:02
  • @theonlygusti proc is a special purpose filesystem (collection of files) that provide information about the kernel's internal state. I believe it stands for processes (see also sysfs which provides information about things others than processes). The reason it is relevant is written by kernel developers, so may well reflect the language that they use which might be a little more formal. – Att Righ Jan 14 '18 at 20:28

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.