E-r*_*ich 6 linux init-script busybox init
我有一个包含inittab以下条目的文件:
console::askfirst:-/bin/ash
Run Code Online (Sandbox Code Playgroud)
根据此手册页,流程字段中的“+”字符表示
init不会对该进程进行 utmp 和 wtmp 计算。
但是,它没有说明“-”字符。进程字段中的“-”字符有什么作用?
连字符似乎是 Busybox 特定的功能(就像“askfirst”一样,这是我发现您正在使用 Busybox 的方式)。该例子的inittab文件中说:
# /bin/sh invocations on selected ttys
#
# Note below that we prefix the shell commands with a "-" to indicate to the
# shell that it is supposed to be a login shell. Normally this is handled by
# login, but since we are bypassing login in this case, BusyBox lets you do
# this yourself...
#
# Start an "askfirst" shell on the console (whatever that may be)
::askfirst:-/bin/sh
Run Code Online (Sandbox Code Playgroud)
因此,它将 shell 作为登录 shell 启动(通过以连字符开头 argv[0])。登录 shell 的含义超出了本问题的范围,但通常至少意味着它将执行不同的启动文件(即~/.profile)。
在 argv[0] 中使用连字符而不是正确的命令行标志来告诉 shell 它是登录 shell 的约定是一个古老的约定 - 它至少可以追溯到第二版 UNIX。(argv[0] 只是"-"用于登录 shell,直到第六版,然后才更改为"-/bin/sh")