有没有一种方法可以让我从 shell 脚本执行应用程序但不创建另一个进程。我希望它看起来只有一个过程。我的 shell 脚本是否被新进程替换,或者在被调用的应用程序结束后是否继续运行,这都无关紧要。
这也应该可以解决我之前的问题:https://askubuntu.com/questions/247632/is-there-a-way-to-associate-additional-application-launcher-with-an-app
非常感谢您的帮助。
答案1
您可以使用以下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.
例子:
user@host:~$ PS1="supershell$ "
supershell$ bash
user@host:~$ PS1="subshell$ "
subshell$ exec echo hello
hello
supershell$
可以看到,子shell被替换成了echo
。