In the man page for the ar
utility, I see the following line.
If you wish, you may begin the first command-line argument with a dash.
However, there is no further mention of the dash anywhere else in the man page. Since I have seen ar
commands both with and without the dash, this leaves the unanswered question.
What effect, if any, does the prefixing the first command-line argument with a -
have?
Moreover, if I want to maintain portability across systems, is it safer to have the -
or not have the -
?
In terms of the ar
found in GNU binutils
, not using the dash has the very small impact of slowing down the startup of your processing.
If you examine the source code of said beast, you'll see very early on in the startup a call to decode_options()
with the following code:
/* Convert old-style tar call by exploding option element and rearranging
options accordingly. */
if (argc > 1 && argv[1][0] != '-')
{
int new_argc; /* argc value for rearranged arguments */
char **new_argv; /* argv value for rearranged arguments */
char *const *in; /* cursor into original argv */
char **out; /* cursor into rearranged argv */
const char *letter; /* cursor into old option letters */
char buffer[3]; /* constructed option buffer */
/* Initialize a constructed option. */
buffer[0] = '-';
buffer[2] = '\0';
/* Allocate a new argument array, and copy program name in it. */
new_argc = argc - 1 + strlen (argv[1]);
new_argv = xmalloc ((new_argc + 1) * sizeof (*argv));
in = argv;
out = new_argv;
*out++ = *in++;
/* Copy each old letter option as a separate option. */
for (letter = *in++; *letter; letter++)
{
buffer[1] = *letter;
*out++ = xstrdup (buffer);
}
So, if you provide an old-style option such as with ar pax diablo
, it will auto-magically turn that into ar -p -a -x diablo
before continuing. By the way, pax
is probably not a valid option set, I've just used it because I'm too lazy to go look at the man
page - but apparently I have no issue spending an inordinate amount of time explaining my decision :-)
In terms of maximum portability then, it appears you would be better off using the non--
arguments since GNU ar
will handle both that and the new form, while older ar
variants will most likely not handle the new form.
But, and this may simply be my CDO(a) tendencies, I'd just go ahead and use the new form on the assumption that I don't really want to support systems so old that they don't have the latest GNU stuff.
(a) Just like OCD, but ordered in the correct damn way :-)