History of ‘argv’ in Command Line Arguments – Origin and Usage

command lineentry-pointhistory

It seems like Python, PHP, and Ruby all use the name "argv" to refer to the list of command line arguments. Where does the name "argv" come from? Why not something like "args"?

My guess is that it comes from C, where the v would stand for "vector". Wikipedia has a footnote that says:

the vector term in this variable's name is used in traditional sense
to refer to strings.

However, there isn't any source for this info. Really, I'm curious if it has roots that trace even farther back. Did C use it because something before that used it?

Best Answer

While the other answers note that argv comes from C, where did C get the idea to call an array a "vector"?

Directly, it came from BCPL. Though argv refers to the vector of (string) arguments, BCPL did have strings stored in vectors, but they were string literals and they worked like Pascal strings. The vector had two elements: the length at literal!0 and the characters at literal!1. According to Clive Feather, strings were manipulated by "unpacking" them into character arrays, transforming the array then "repacking" them into strings: compare this with C where strings are character arrays.

So yes, C used v for vector because something else had done so before. Now, did anything before BCPL use vector in this way? BCPL was itself a simplification of the "Cambridge[or Combined] Programming Language": this used vector as a synonym for a 1-dimensional array and matrix as a synonym for a 2-dimensional array. This is consistent with the notation in mathematics of vectors and matrices, though in CPL they're just handy mnemonics and don't have any of the properties associated with the mathematical structures.

Can we push back further in time regarding computing languages? One potential branch of our trail runs cold. CPL was heavily influenced by Algol 60 (the 1963 update). Now ALGOL 68 had types that were described as "packed vectors", such as bits and bytes: but these weren't in earlier releases of Algol which just had ARRAY referring to array. As BCPL comes from 1966, CPL must have been before that (but after 1963): ALGOL 68 (standardised in 1968 and 1973) cannot have been a direct influence.

On the other hand, Main Features of CPL also makes reference to McCarthy's LISP system. While this doesn't use vector to refer to a data structure in the system itself, those being S-expressions, M-expressions and L-expressions (L-expressions are strings, so any association between vector and string has disappeared), it does use vector in another sense to represent the "values of a number of variables" representing "the state of the machine at any time". So we have evidence for an assumption made in the comments: that use of the word 'vector' to mean 'array' in computing comes from application of the similar term in mathematics.