首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >终端模拟器总是通过shell间接执行程序吗?

终端模拟器总是通过shell间接执行程序吗?
EN

Unix & Linux用户
提问于 2018-11-28 00:13:43
回答 2查看 765关注 0票数 1

终端模拟器总是通过shell间接执行程序吗?

例如,当我们打开终端模拟器窗口时,它会自动执行一个shell,并且我们只能在shell中键入命令。

例如,当程序直接在终端模拟器上运行时,如

代码语言:javascript
运行
复制
xterm -e "echo hello; sleep 5"

xterm是通过shell间接执行程序,还是直接不带shell执行程序?

EN

回答 2

Unix & Linux用户

发布于 2018-11-28 15:48:21

在您的示例中,使用-e选项,然后xterm将启动一个shell,手动声明如下。

可以重写xterm对shell的默认搜索,因此您可以为此提供自己的程序,但是当您重写shell时,您不能使用-e选项。当您重写shell时,您的shell将直接由xterm运行(fork() + exec())。

以下是相关章节,

代码语言:javascript
运行
复制
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.

代码语言:javascript
运行
复制
-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.

只要看看你在执行什么,

代码语言:javascript
运行
复制
"echo hello; sleep 5"

它是解析该字符串的shell,它使用PATH env变量查找这两个命令,并意识到它确实是用分号分隔的两个命令,xterm没有这样做!

票数 2
EN

Unix & Linux用户

发布于 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"没有。

票数 0
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/484548

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档