终端模拟器总是通过shell间接执行程序吗?
例如,当我们打开终端模拟器窗口时,它会自动执行一个shell,并且我们只能在shell中键入命令。
例如,当程序直接在终端模拟器上运行时,如
xterm -e "echo hello; sleep 5"
xterm
是通过shell间接执行程序,还是直接不带shell执行程序?
发布于 2018-11-28 15:48:21
在您的示例中,使用-e
选项,然后xterm
将启动一个shell,手动声明如下。
可以重写xterm对shell的默认搜索,因此您可以为此提供自己的程序,但是当您重写shell时,您不能使用-e选项。当您重写shell时,您的shell将直接由xterm运行(fork() + exec()
)。
以下是相关章节,
One parameter (after all options) may be given. That overrides xterm's built-in choice of
shell program. Normally xterm checks the SHELL variable. If that is not set, xterm tries
to use the shell program specified in the password file. If that is not set, xterm uses
/bin/sh. If the parameter is not a relative path, i.e., beginning with “./” or “../”, xterm
looks for the file in the user's PATH. In either case, it constructs an absolute path. The
-e option cannot be used with this parameter since it uses all parameters following the
option.
和
-e program [ arguments ... ]
This option specifies the program (and its command line arguments) to be run in the
xterm window. It also sets the window title and icon name to be the basename of the
program being executed if neither -T nor -n are given on the command line. This
must be the last option on the command line.
只要看看你在执行什么,
"echo hello; sleep 5"
它是解析该字符串的shell,它使用PATH
env变量查找这两个命令,并意识到它确实是用分号分隔的两个命令,xterm
没有这样做!
发布于 2018-11-28 00:18:49
根据手册,您可以禁用带有参数+ls
的登录shell:
+ls This option indicates that the shell that is started should not be a login shell (i.e., it will be a normal “subshell”).
因此,xterm -e "echo hello"
生成了一个shell,但xterm +ls -e "echo hello"
没有。
https://unix.stackexchange.com/questions/484548
复制相似问题