Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

exec options : what is zeroth argument to command?

Tags:

linux

bash

shell

help exec

indicates this option to exec

-a name   pass NAME as the zeroth argument to COMMAND

What is Zeroth argument to the command ?

-l                place a dash in the zeroth argument to COMMAND

What does placing dash in zeroth argument mean ?

like image 819
Ankur Agarwal Avatar asked Oct 29 '25 18:10

Ankur Agarwal


1 Answers

As you've been told, the zeroth argument is what appears in argv[0], conventionally the name of the program being executed. However, 'conventionally' means that anything can appear there, and the -a option gives you a way to control what appears there.

$ (exec -a sharktank ps -t ttys003)
  PID TTY           TIME CMD
  574 ttys003    0:00.02 login -pf jleffler
  575 ttys003    0:00.07 -bash
 9507 ttys003    0:00.00 sharktank -t ttys003
$

The -l option adds a dash before the command name (zeroth argument). This is a convention used by the login program to tell shells that they are 'login shells' and should process profiles or equivalent.

For example:

$ ps
  PID TTY           TIME CMD
37617 ttys000    0:00.01 -bash
$ bash
$ ps
  PID TTY           TIME CMD
37617 ttys000    0:00.02 -bash
37672 ttys000    0:00.01 bash
$ exit
exit
$ ps
  PID TTY           TIME CMD
37617 ttys000    0:00.02 -bash
$

The dash indicates that the shell for process 37617 was the initial login shell for the terminal window. This has been how Unix shells detected that they were login shells back to at least 7th Edition (Version 7) UNIX, though it was not necessarily clearly documented.

like image 118
Jonathan Leffler Avatar answered Nov 01 '25 17:11

Jonathan Leffler