Всегда ли эмулятор терминала выполняет программу опосредованно через оболочку?

То, что у вас есть, работает в моей системе.

    user:~$ groups test;
    test : test
    user:~$ groups
    user adm cdrom sudo dip www-data plugdev lpadmin sambashare davfs2 wireshark
    user:~$ sudo usermod -a -G $(id -Gn | tr " " ",") test
    user:~$ groups test
    test : test adm cdrom sudo dip www-data plugdev lpadmin user sambashare davfs2 wireshark
1
28.11.2018, 17:19
2 ответа

Это зависит от эмулятора терминала.

xtermсначала вызовет execvp(2)с аргументами, переданными -e, но если это не удастся и после -eбудет один аргумент command, он также попытается $SHELL -c command.

mltermи rxvtпросто выдадут ошибку, если execvpне работает.

Если мой второй абзац вас не убедил, вы можете попробовать это:

$ mkdir /tmp/tbin; ln -s /usr/bin/vi '/tmp/tbin/echo hello; sleep 5'
$ PATH=$PATH:/tmp/tbin xterm -e 'echo hello; sleep 5'

Или посмотрите на источник .

4
27.01.2020, 23:14

В вашем примере, используя опцию -e, xtermзапустит оболочку, это указано в руководстве.

Можно переопределить поиск оболочки по умолчанию в xterm, поэтому вы можете предоставить для этого свою собственную программу, но при переопределении оболочки вы не можете использовать опцию -e. Когда вы переопределяете оболочку, тогда ваша оболочка запускается(fork() + exec())непосредственно xterm.

Вот соответствующие разделы,

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"

Эту строку анализирует оболочка, она использует переменную PATHenv для поиска двух команд и понимает, что это действительно две команды, разделенные точкой с запятой, xtermэтого не делает!

2
27.01.2020, 23:14

Теги

Похожие вопросы