Linux exec选项:命令的第0个参数是什么?

Linux exec选项:命令的第0个参数是什么?,linux,bash,shell,Linux,Bash,Shell,将此选项指示给exec help exec 命令的第0个参数是什么 -a name pass NAME as the zeroth argument to COMMAND 在第0个参数中放置破折号意味着什么?它是用于调用脚本的名称 从命令行运行时,可以通过链接调用脚本来更改它。在Mac OS X上比较: -l place a dash in the zeroth argument to COMMAND 正如您所知,第0个参数是出现在argv[0]中的参数,

将此选项指示给exec

help exec
命令的第0个参数是什么

-a name   pass NAME as the zeroth argument to COMMAND

在第0个参数中放置破折号意味着什么?

它是用于调用脚本的名称

从命令行运行时,可以通过链接调用脚本来更改它。

在Mac OS X上比较:

-l                place a dash in the zeroth argument to COMMAND

正如您所知,第0个参数是出现在
argv[0]
中的参数,通常是正在执行的程序的名称。然而,“常规”意味着任何东西都可以出现在那里,而
-a
选项为您提供了一种控制出现在那里的内容的方法

(exec -a foo sh -c 'echo $0')
(exec -l -a foo sh -c 'echo $0')
(exec -l -a foo sh -c 'echo $0' arg0)
-l
选项在命令名(第零个参数)前添加破折号。这是
login
程序使用的一种约定,用于告诉shell它们是“登录shell”,应该处理概要文件或等效文件

例如:

$ (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
$

破折号表示进程37617的shell是终端窗口的初始登录shell。这就是Unix Shell检测到它们至少是第7版(第7版)Unix的登录Shell的方式,尽管不一定有明确的文档记录。

谢谢。我怎么忘记了
basename$0
(echo hello;exec-l-a testps ps-o pid,ppid,cmd)(echo hello;exec-a testps ps-o pid,ppid,cmd)(echo hello;exec-a testps ps-o pid,ppid,cmd)(echo hello;exec-l-a testps ps-o pid,ppid,cmd)(echo hello;exec-l-a testps-o pid,ppid,cmd)
$ 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
$