从 shell 脚本运行程序但仅作为一个进程运行?

zub*_*out 13 bash programming process

有没有办法可以从 shell 脚本执行应用程序,但不能创建另一个进程。我希望它看起来像一个进程。我的 shell 脚本是否被新进程替换或者在被调用的应用程序结束后它是否会继续都无关紧要。
这也应该解决我之前的问题:https : //askubuntu.com/questions/247632/is-there-a-way-to-associate-additional-application-launcher-with-an-app
非常感谢您的帮助.

And*_*ini 7

您可以使用以下exec命令:

$ help exec
exec: exec [-cl] [-a name] [command [arguments ...]] [redirection ...]
    Replace the shell with the given command.

    Execute COMMAND, replacing this shell with the specified program.
    ARGUMENTS become the arguments to COMMAND.  If COMMAND is not specified,
    any redirections take effect in the current shell.

    Options:
      -a name   pass NAME as the zeroth argument to COMMAND
      -c        execute COMMAND with an empty environment
      -l        place a dash in the zeroth argument to COMMAND

    If the command cannot be executed, a non-interactive shell exits, unless
    the shell option `execfail' is set.

    Exit Status:
    Returns success unless COMMAND is not found or a redirection error occurs.
Run Code Online (Sandbox Code Playgroud)

例子:

user@host:~$ PS1="supershell$ "
supershell$ bash
user@host:~$ PS1="subshell$ "
subshell$ exec echo hello
hello
supershell$ 
Run Code Online (Sandbox Code Playgroud)

如您所见,子外壳被替换为echo.

  • 所以,我读了你之前的问题,看起来你误解了一些事情。您将_process_ 与_zeroth 参数_ 与_PID_ 与_dash 启动器_ 混淆。而且你也问错了问题。您首先要问的是:**dash 如何将启动器与进程相关联?** 一旦您找到该问题的答案,您还将找到原始问题的答案。 (2认同)