Does a terminal emulator execute a program always indirectly via shell?











up vote
1
down vote

favorite
1












Does a terminal emulator execute a program always indirectly via shell?



For example, when we open a terminal emulator window, it automatically executes a shell, and we can only type commands in the shell.



For example, when running a program directly on a terminal emulator, such as



xterm -e "echo hello; sleep 5"


Does xterm execute the program, indirectly via shell, or directly without shell?










share|improve this question




























    up vote
    1
    down vote

    favorite
    1












    Does a terminal emulator execute a program always indirectly via shell?



    For example, when we open a terminal emulator window, it automatically executes a shell, and we can only type commands in the shell.



    For example, when running a program directly on a terminal emulator, such as



    xterm -e "echo hello; sleep 5"


    Does xterm execute the program, indirectly via shell, or directly without shell?










    share|improve this question


























      up vote
      1
      down vote

      favorite
      1









      up vote
      1
      down vote

      favorite
      1






      1





      Does a terminal emulator execute a program always indirectly via shell?



      For example, when we open a terminal emulator window, it automatically executes a shell, and we can only type commands in the shell.



      For example, when running a program directly on a terminal emulator, such as



      xterm -e "echo hello; sleep 5"


      Does xterm execute the program, indirectly via shell, or directly without shell?










      share|improve this question















      Does a terminal emulator execute a program always indirectly via shell?



      For example, when we open a terminal emulator window, it automatically executes a shell, and we can only type commands in the shell.



      For example, when running a program directly on a terminal emulator, such as



      xterm -e "echo hello; sleep 5"


      Does xterm execute the program, indirectly via shell, or directly without shell?







      xterm terminal-emulator






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 28 at 15:19









      slm

      245k66505671




      245k66505671










      asked Nov 28 at 0:13









      Tim

      25.1k72243444




      25.1k72243444






















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          4
          down vote



          accepted










          It depends on the terminal emulator.



          xterm will first call execvp(2) with the arguments given to -e, but if that fails and there is a single command argument following -e, it will also try $SHELL -c command.



          mlterm and rxvt will just error out if the execvp fails.



          If my second paragraph didn't convince you, you can try this:



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


          Or look at the source.






          share|improve this answer






























            up vote
            2
            down vote













            With your example, using the -e option, then xterm will start a shell, the manual states this.



            It is possible to override xterm's default search for a shell, so you could supply your own program for this, but when you override the shell you cannot use the -e option. When you override the shell, then the your shell is run (fork() + exec()) directly by xterm.



            Here are the relevant sections,



            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.


            and



            -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.


            And just looking at what you are executing,



            "echo hello; sleep 5"


            It's the shell which parses that string, it uses the PATH env variable to find the two commands, and realises that it is indeed two commands separated with the semi colon, xterm doesn't do that!






            share|improve this answer























            • Thanks. Very nice.
              – Tim
              2 days ago


















            up vote
            0
            down vote













            According to the manual, you can disable login shell with parameter +ls:




               +ls     This option indicates that the shell that is started should not
            be a login shell (i.e., it will be a normal “subshell”).



            So xterm -e "echo hello" spawns a shell, but xterm +ls -e "echo hello" does not.






            share|improve this answer





















            • xterm +ls -e "echo hello" executes echo hello indirectly by a shell, doesn't it?
              – Tim
              Nov 28 at 0:50












            • That is, xterm +ls -e "echo hello" executes a shell to execute echo hello, doesn't it?
              – Tim
              Nov 28 at 0:59








            • 2




              You're confusing "login shell" vs. "non-login shell" with having a shell at all... xterm +ls -e '...' still runs a shell, just not a login shell. You can easily check that by running a command that needs the shell (like something with ;) or by using, say, ps -p $$
              – Filipe Brandenburger
              Nov 28 at 1:28











            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "106"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f484548%2fdoes-a-terminal-emulator-execute-a-program-always-indirectly-via-shell%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            4
            down vote



            accepted










            It depends on the terminal emulator.



            xterm will first call execvp(2) with the arguments given to -e, but if that fails and there is a single command argument following -e, it will also try $SHELL -c command.



            mlterm and rxvt will just error out if the execvp fails.



            If my second paragraph didn't convince you, you can try this:



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


            Or look at the source.






            share|improve this answer



























              up vote
              4
              down vote



              accepted










              It depends on the terminal emulator.



              xterm will first call execvp(2) with the arguments given to -e, but if that fails and there is a single command argument following -e, it will also try $SHELL -c command.



              mlterm and rxvt will just error out if the execvp fails.



              If my second paragraph didn't convince you, you can try this:



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


              Or look at the source.






              share|improve this answer

























                up vote
                4
                down vote



                accepted







                up vote
                4
                down vote



                accepted






                It depends on the terminal emulator.



                xterm will first call execvp(2) with the arguments given to -e, but if that fails and there is a single command argument following -e, it will also try $SHELL -c command.



                mlterm and rxvt will just error out if the execvp fails.



                If my second paragraph didn't convince you, you can try this:



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


                Or look at the source.






                share|improve this answer














                It depends on the terminal emulator.



                xterm will first call execvp(2) with the arguments given to -e, but if that fails and there is a single command argument following -e, it will also try $SHELL -c command.



                mlterm and rxvt will just error out if the execvp fails.



                If my second paragraph didn't convince you, you can try this:



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


                Or look at the source.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 28 at 3:05

























                answered Nov 28 at 2:47









                mosvy

                5,011323




                5,011323
























                    up vote
                    2
                    down vote













                    With your example, using the -e option, then xterm will start a shell, the manual states this.



                    It is possible to override xterm's default search for a shell, so you could supply your own program for this, but when you override the shell you cannot use the -e option. When you override the shell, then the your shell is run (fork() + exec()) directly by xterm.



                    Here are the relevant sections,



                    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.


                    and



                    -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.


                    And just looking at what you are executing,



                    "echo hello; sleep 5"


                    It's the shell which parses that string, it uses the PATH env variable to find the two commands, and realises that it is indeed two commands separated with the semi colon, xterm doesn't do that!






                    share|improve this answer























                    • Thanks. Very nice.
                      – Tim
                      2 days ago















                    up vote
                    2
                    down vote













                    With your example, using the -e option, then xterm will start a shell, the manual states this.



                    It is possible to override xterm's default search for a shell, so you could supply your own program for this, but when you override the shell you cannot use the -e option. When you override the shell, then the your shell is run (fork() + exec()) directly by xterm.



                    Here are the relevant sections,



                    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.


                    and



                    -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.


                    And just looking at what you are executing,



                    "echo hello; sleep 5"


                    It's the shell which parses that string, it uses the PATH env variable to find the two commands, and realises that it is indeed two commands separated with the semi colon, xterm doesn't do that!






                    share|improve this answer























                    • Thanks. Very nice.
                      – Tim
                      2 days ago













                    up vote
                    2
                    down vote










                    up vote
                    2
                    down vote









                    With your example, using the -e option, then xterm will start a shell, the manual states this.



                    It is possible to override xterm's default search for a shell, so you could supply your own program for this, but when you override the shell you cannot use the -e option. When you override the shell, then the your shell is run (fork() + exec()) directly by xterm.



                    Here are the relevant sections,



                    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.


                    and



                    -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.


                    And just looking at what you are executing,



                    "echo hello; sleep 5"


                    It's the shell which parses that string, it uses the PATH env variable to find the two commands, and realises that it is indeed two commands separated with the semi colon, xterm doesn't do that!






                    share|improve this answer














                    With your example, using the -e option, then xterm will start a shell, the manual states this.



                    It is possible to override xterm's default search for a shell, so you could supply your own program for this, but when you override the shell you cannot use the -e option. When you override the shell, then the your shell is run (fork() + exec()) directly by xterm.



                    Here are the relevant sections,



                    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.


                    and



                    -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.


                    And just looking at what you are executing,



                    "echo hello; sleep 5"


                    It's the shell which parses that string, it uses the PATH env variable to find the two commands, and realises that it is indeed two commands separated with the semi colon, xterm doesn't do that!







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited 2 days ago

























                    answered Nov 28 at 15:48









                    X Tian

                    7,57111936




                    7,57111936












                    • Thanks. Very nice.
                      – Tim
                      2 days ago


















                    • Thanks. Very nice.
                      – Tim
                      2 days ago
















                    Thanks. Very nice.
                    – Tim
                    2 days ago




                    Thanks. Very nice.
                    – Tim
                    2 days ago










                    up vote
                    0
                    down vote













                    According to the manual, you can disable login shell with parameter +ls:




                       +ls     This option indicates that the shell that is started should not
                    be a login shell (i.e., it will be a normal “subshell”).



                    So xterm -e "echo hello" spawns a shell, but xterm +ls -e "echo hello" does not.






                    share|improve this answer





















                    • xterm +ls -e "echo hello" executes echo hello indirectly by a shell, doesn't it?
                      – Tim
                      Nov 28 at 0:50












                    • That is, xterm +ls -e "echo hello" executes a shell to execute echo hello, doesn't it?
                      – Tim
                      Nov 28 at 0:59








                    • 2




                      You're confusing "login shell" vs. "non-login shell" with having a shell at all... xterm +ls -e '...' still runs a shell, just not a login shell. You can easily check that by running a command that needs the shell (like something with ;) or by using, say, ps -p $$
                      – Filipe Brandenburger
                      Nov 28 at 1:28















                    up vote
                    0
                    down vote













                    According to the manual, you can disable login shell with parameter +ls:




                       +ls     This option indicates that the shell that is started should not
                    be a login shell (i.e., it will be a normal “subshell”).



                    So xterm -e "echo hello" spawns a shell, but xterm +ls -e "echo hello" does not.






                    share|improve this answer





















                    • xterm +ls -e "echo hello" executes echo hello indirectly by a shell, doesn't it?
                      – Tim
                      Nov 28 at 0:50












                    • That is, xterm +ls -e "echo hello" executes a shell to execute echo hello, doesn't it?
                      – Tim
                      Nov 28 at 0:59








                    • 2




                      You're confusing "login shell" vs. "non-login shell" with having a shell at all... xterm +ls -e '...' still runs a shell, just not a login shell. You can easily check that by running a command that needs the shell (like something with ;) or by using, say, ps -p $$
                      – Filipe Brandenburger
                      Nov 28 at 1:28













                    up vote
                    0
                    down vote










                    up vote
                    0
                    down vote









                    According to the manual, you can disable login shell with parameter +ls:




                       +ls     This option indicates that the shell that is started should not
                    be a login shell (i.e., it will be a normal “subshell”).



                    So xterm -e "echo hello" spawns a shell, but xterm +ls -e "echo hello" does not.






                    share|improve this answer












                    According to the manual, you can disable login shell with parameter +ls:




                       +ls     This option indicates that the shell that is started should not
                    be a login shell (i.e., it will be a normal “subshell”).



                    So xterm -e "echo hello" spawns a shell, but xterm +ls -e "echo hello" does not.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 28 at 0:18









                    Ipor Sircer

                    10.3k11024




                    10.3k11024












                    • xterm +ls -e "echo hello" executes echo hello indirectly by a shell, doesn't it?
                      – Tim
                      Nov 28 at 0:50












                    • That is, xterm +ls -e "echo hello" executes a shell to execute echo hello, doesn't it?
                      – Tim
                      Nov 28 at 0:59








                    • 2




                      You're confusing "login shell" vs. "non-login shell" with having a shell at all... xterm +ls -e '...' still runs a shell, just not a login shell. You can easily check that by running a command that needs the shell (like something with ;) or by using, say, ps -p $$
                      – Filipe Brandenburger
                      Nov 28 at 1:28


















                    • xterm +ls -e "echo hello" executes echo hello indirectly by a shell, doesn't it?
                      – Tim
                      Nov 28 at 0:50












                    • That is, xterm +ls -e "echo hello" executes a shell to execute echo hello, doesn't it?
                      – Tim
                      Nov 28 at 0:59








                    • 2




                      You're confusing "login shell" vs. "non-login shell" with having a shell at all... xterm +ls -e '...' still runs a shell, just not a login shell. You can easily check that by running a command that needs the shell (like something with ;) or by using, say, ps -p $$
                      – Filipe Brandenburger
                      Nov 28 at 1:28
















                    xterm +ls -e "echo hello" executes echo hello indirectly by a shell, doesn't it?
                    – Tim
                    Nov 28 at 0:50






                    xterm +ls -e "echo hello" executes echo hello indirectly by a shell, doesn't it?
                    – Tim
                    Nov 28 at 0:50














                    That is, xterm +ls -e "echo hello" executes a shell to execute echo hello, doesn't it?
                    – Tim
                    Nov 28 at 0:59






                    That is, xterm +ls -e "echo hello" executes a shell to execute echo hello, doesn't it?
                    – Tim
                    Nov 28 at 0:59






                    2




                    2




                    You're confusing "login shell" vs. "non-login shell" with having a shell at all... xterm +ls -e '...' still runs a shell, just not a login shell. You can easily check that by running a command that needs the shell (like something with ;) or by using, say, ps -p $$
                    – Filipe Brandenburger
                    Nov 28 at 1:28




                    You're confusing "login shell" vs. "non-login shell" with having a shell at all... xterm +ls -e '...' still runs a shell, just not a login shell. You can easily check that by running a command that needs the shell (like something with ;) or by using, say, ps -p $$
                    – Filipe Brandenburger
                    Nov 28 at 1:28


















                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Unix & Linux Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f484548%2fdoes-a-terminal-emulator-execute-a-program-always-indirectly-via-shell%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Accessing regular linux commands in Huawei's Dopra Linux

                    Can't connect RFCOMM socket: Host is down

                    Kernel panic - not syncing: Fatal Exception in Interrupt