Mysteries of xinitrc - what can and cannot be there

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












0















Please,

can someone shed some light for me on .xinitrc file? I struggle to find a good manual to answer a couple of my practical questions:



  • It declared itself as general Bash script but in fact it is not.

  • Why some command require exec and some not?

  • What is this exec command anyway?

  • Is it a binary or a syntactic construct specific to xinitrc?

  • What can be run by exec and what not?

  • How to set environmental variables correctly?

Most users of mainstream distros does not have to even know about xinitrc, and same was true for me, until I had to setup Kodi "makeshift" shell; using super minimalist window manager TWM and launching Kodi full screen, because kodi-standalone shell does not work for me.



But back to the xinitrc:



Working example:



#!/bin/bash
/usr/bin/twm &
sleep 1
exec xterm


Why twm and sleep do not need exec but xterm does?



Not working example:



#!/bin/bash
/usr/bin/twm &
sleep 1
exec WINDOWING=x11 /usr/bin/kodi -geometry +0+0


Here exec executed only WINDOWING=x11 but ignored the rest of the line. I made it working only by wrapping WINDOWING=x11 /usr/bin/kodi -geometry +0+0 into another Bash script, this time an ordinary one, and that one put as the only argument to exec; then it finally worked.










share|improve this question













migrated from serverfault.com Mar 4 at 2:12


This question came from our site for system and network administrators.













  • 2





    stackoverflow.com/q/22869637/1068283

    – Michael Hampton
    Mar 4 at 2:12











  • Why do you use exec? just run it on this way: WINDOWING=x11 /usr/bin/kodi -geometry +0+0

    – Romeo Ninov
    Mar 4 at 7:04















0















Please,

can someone shed some light for me on .xinitrc file? I struggle to find a good manual to answer a couple of my practical questions:



  • It declared itself as general Bash script but in fact it is not.

  • Why some command require exec and some not?

  • What is this exec command anyway?

  • Is it a binary or a syntactic construct specific to xinitrc?

  • What can be run by exec and what not?

  • How to set environmental variables correctly?

Most users of mainstream distros does not have to even know about xinitrc, and same was true for me, until I had to setup Kodi "makeshift" shell; using super minimalist window manager TWM and launching Kodi full screen, because kodi-standalone shell does not work for me.



But back to the xinitrc:



Working example:



#!/bin/bash
/usr/bin/twm &
sleep 1
exec xterm


Why twm and sleep do not need exec but xterm does?



Not working example:



#!/bin/bash
/usr/bin/twm &
sleep 1
exec WINDOWING=x11 /usr/bin/kodi -geometry +0+0


Here exec executed only WINDOWING=x11 but ignored the rest of the line. I made it working only by wrapping WINDOWING=x11 /usr/bin/kodi -geometry +0+0 into another Bash script, this time an ordinary one, and that one put as the only argument to exec; then it finally worked.










share|improve this question













migrated from serverfault.com Mar 4 at 2:12


This question came from our site for system and network administrators.













  • 2





    stackoverflow.com/q/22869637/1068283

    – Michael Hampton
    Mar 4 at 2:12











  • Why do you use exec? just run it on this way: WINDOWING=x11 /usr/bin/kodi -geometry +0+0

    – Romeo Ninov
    Mar 4 at 7:04













0












0








0








Please,

can someone shed some light for me on .xinitrc file? I struggle to find a good manual to answer a couple of my practical questions:



  • It declared itself as general Bash script but in fact it is not.

  • Why some command require exec and some not?

  • What is this exec command anyway?

  • Is it a binary or a syntactic construct specific to xinitrc?

  • What can be run by exec and what not?

  • How to set environmental variables correctly?

Most users of mainstream distros does not have to even know about xinitrc, and same was true for me, until I had to setup Kodi "makeshift" shell; using super minimalist window manager TWM and launching Kodi full screen, because kodi-standalone shell does not work for me.



But back to the xinitrc:



Working example:



#!/bin/bash
/usr/bin/twm &
sleep 1
exec xterm


Why twm and sleep do not need exec but xterm does?



Not working example:



#!/bin/bash
/usr/bin/twm &
sleep 1
exec WINDOWING=x11 /usr/bin/kodi -geometry +0+0


Here exec executed only WINDOWING=x11 but ignored the rest of the line. I made it working only by wrapping WINDOWING=x11 /usr/bin/kodi -geometry +0+0 into another Bash script, this time an ordinary one, and that one put as the only argument to exec; then it finally worked.










share|improve this question














Please,

can someone shed some light for me on .xinitrc file? I struggle to find a good manual to answer a couple of my practical questions:



  • It declared itself as general Bash script but in fact it is not.

  • Why some command require exec and some not?

  • What is this exec command anyway?

  • Is it a binary or a syntactic construct specific to xinitrc?

  • What can be run by exec and what not?

  • How to set environmental variables correctly?

Most users of mainstream distros does not have to even know about xinitrc, and same was true for me, until I had to setup Kodi "makeshift" shell; using super minimalist window manager TWM and launching Kodi full screen, because kodi-standalone shell does not work for me.



But back to the xinitrc:



Working example:



#!/bin/bash
/usr/bin/twm &
sleep 1
exec xterm


Why twm and sleep do not need exec but xterm does?



Not working example:



#!/bin/bash
/usr/bin/twm &
sleep 1
exec WINDOWING=x11 /usr/bin/kodi -geometry +0+0


Here exec executed only WINDOWING=x11 but ignored the rest of the line. I made it working only by wrapping WINDOWING=x11 /usr/bin/kodi -geometry +0+0 into another Bash script, this time an ordinary one, and that one put as the only argument to exec; then it finally worked.







xorg






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 3 at 22:54









EspinosaEspinosa

1234




1234




migrated from serverfault.com Mar 4 at 2:12


This question came from our site for system and network administrators.









migrated from serverfault.com Mar 4 at 2:12


This question came from our site for system and network administrators.









  • 2





    stackoverflow.com/q/22869637/1068283

    – Michael Hampton
    Mar 4 at 2:12











  • Why do you use exec? just run it on this way: WINDOWING=x11 /usr/bin/kodi -geometry +0+0

    – Romeo Ninov
    Mar 4 at 7:04












  • 2





    stackoverflow.com/q/22869637/1068283

    – Michael Hampton
    Mar 4 at 2:12











  • Why do you use exec? just run it on this way: WINDOWING=x11 /usr/bin/kodi -geometry +0+0

    – Romeo Ninov
    Mar 4 at 7:04







2




2





stackoverflow.com/q/22869637/1068283

– Michael Hampton
Mar 4 at 2:12





stackoverflow.com/q/22869637/1068283

– Michael Hampton
Mar 4 at 2:12













Why do you use exec? just run it on this way: WINDOWING=x11 /usr/bin/kodi -geometry +0+0

– Romeo Ninov
Mar 4 at 7:04





Why do you use exec? just run it on this way: WINDOWING=x11 /usr/bin/kodi -geometry +0+0

– Romeo Ninov
Mar 4 at 7:04










1 Answer
1






active

oldest

votes


















3














The exec command replaces the current shell process with the process resulting from executing the given command. Without exec, control would be handed back to the waiting shell session once the command terminates. With exec, the current shell is replaced, so no further commands would be run from your script from that point on.



The ~/.xinitrc file is a shell script. It starts the window manager (twm in your case), and possibly other X11 clients that you may want to start initially (like xterm or some other terminal, and xeyes, obviously). There is no special syntax for this script apart from that it should be a valid script (since it's run by a shell script interpreter).



In your first example, you use



exec xterm


This replaces the current shell process with xterm. Without exec, you would have the exact same visible effect, but the .xinitrc script would hang around in the background waiting for xterm to terminate before itself terminating (since that was the last command in the file).



Note that if you had done exec twm, the shell would have replaced itself with twm which means that it would not be able to run the other commands in the script. This is why you instead start twm as a background process (with & at the end). The sleep is there to allow twm to start up properly before starting the terminal. I don't think this is strictly necessary. In fact, if you don't need window decorations or to be able to move windows around or resize them, there is no need to even run twm or any other window manager (at least not for running a full screen xterm).



In your second example, you use



exec WINDOWING=x11 /usr/bin/kodi -geometry +0+0


Now, the exec command can't be used to set environment variables like that. Instead, you would set and export the WINDOWING variable before invoking kodi:



export WINDOWING=x11
exec /usr/bin/kodi -geometry +0+0





share|improve this answer

























    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',
    autoActivateHeartbeat: false,
    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%2f504188%2fmysteries-of-xinitrc-what-can-and-cannot-be-there%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    The exec command replaces the current shell process with the process resulting from executing the given command. Without exec, control would be handed back to the waiting shell session once the command terminates. With exec, the current shell is replaced, so no further commands would be run from your script from that point on.



    The ~/.xinitrc file is a shell script. It starts the window manager (twm in your case), and possibly other X11 clients that you may want to start initially (like xterm or some other terminal, and xeyes, obviously). There is no special syntax for this script apart from that it should be a valid script (since it's run by a shell script interpreter).



    In your first example, you use



    exec xterm


    This replaces the current shell process with xterm. Without exec, you would have the exact same visible effect, but the .xinitrc script would hang around in the background waiting for xterm to terminate before itself terminating (since that was the last command in the file).



    Note that if you had done exec twm, the shell would have replaced itself with twm which means that it would not be able to run the other commands in the script. This is why you instead start twm as a background process (with & at the end). The sleep is there to allow twm to start up properly before starting the terminal. I don't think this is strictly necessary. In fact, if you don't need window decorations or to be able to move windows around or resize them, there is no need to even run twm or any other window manager (at least not for running a full screen xterm).



    In your second example, you use



    exec WINDOWING=x11 /usr/bin/kodi -geometry +0+0


    Now, the exec command can't be used to set environment variables like that. Instead, you would set and export the WINDOWING variable before invoking kodi:



    export WINDOWING=x11
    exec /usr/bin/kodi -geometry +0+0





    share|improve this answer





























      3














      The exec command replaces the current shell process with the process resulting from executing the given command. Without exec, control would be handed back to the waiting shell session once the command terminates. With exec, the current shell is replaced, so no further commands would be run from your script from that point on.



      The ~/.xinitrc file is a shell script. It starts the window manager (twm in your case), and possibly other X11 clients that you may want to start initially (like xterm or some other terminal, and xeyes, obviously). There is no special syntax for this script apart from that it should be a valid script (since it's run by a shell script interpreter).



      In your first example, you use



      exec xterm


      This replaces the current shell process with xterm. Without exec, you would have the exact same visible effect, but the .xinitrc script would hang around in the background waiting for xterm to terminate before itself terminating (since that was the last command in the file).



      Note that if you had done exec twm, the shell would have replaced itself with twm which means that it would not be able to run the other commands in the script. This is why you instead start twm as a background process (with & at the end). The sleep is there to allow twm to start up properly before starting the terminal. I don't think this is strictly necessary. In fact, if you don't need window decorations or to be able to move windows around or resize them, there is no need to even run twm or any other window manager (at least not for running a full screen xterm).



      In your second example, you use



      exec WINDOWING=x11 /usr/bin/kodi -geometry +0+0


      Now, the exec command can't be used to set environment variables like that. Instead, you would set and export the WINDOWING variable before invoking kodi:



      export WINDOWING=x11
      exec /usr/bin/kodi -geometry +0+0





      share|improve this answer



























        3












        3








        3







        The exec command replaces the current shell process with the process resulting from executing the given command. Without exec, control would be handed back to the waiting shell session once the command terminates. With exec, the current shell is replaced, so no further commands would be run from your script from that point on.



        The ~/.xinitrc file is a shell script. It starts the window manager (twm in your case), and possibly other X11 clients that you may want to start initially (like xterm or some other terminal, and xeyes, obviously). There is no special syntax for this script apart from that it should be a valid script (since it's run by a shell script interpreter).



        In your first example, you use



        exec xterm


        This replaces the current shell process with xterm. Without exec, you would have the exact same visible effect, but the .xinitrc script would hang around in the background waiting for xterm to terminate before itself terminating (since that was the last command in the file).



        Note that if you had done exec twm, the shell would have replaced itself with twm which means that it would not be able to run the other commands in the script. This is why you instead start twm as a background process (with & at the end). The sleep is there to allow twm to start up properly before starting the terminal. I don't think this is strictly necessary. In fact, if you don't need window decorations or to be able to move windows around or resize them, there is no need to even run twm or any other window manager (at least not for running a full screen xterm).



        In your second example, you use



        exec WINDOWING=x11 /usr/bin/kodi -geometry +0+0


        Now, the exec command can't be used to set environment variables like that. Instead, you would set and export the WINDOWING variable before invoking kodi:



        export WINDOWING=x11
        exec /usr/bin/kodi -geometry +0+0





        share|improve this answer















        The exec command replaces the current shell process with the process resulting from executing the given command. Without exec, control would be handed back to the waiting shell session once the command terminates. With exec, the current shell is replaced, so no further commands would be run from your script from that point on.



        The ~/.xinitrc file is a shell script. It starts the window manager (twm in your case), and possibly other X11 clients that you may want to start initially (like xterm or some other terminal, and xeyes, obviously). There is no special syntax for this script apart from that it should be a valid script (since it's run by a shell script interpreter).



        In your first example, you use



        exec xterm


        This replaces the current shell process with xterm. Without exec, you would have the exact same visible effect, but the .xinitrc script would hang around in the background waiting for xterm to terminate before itself terminating (since that was the last command in the file).



        Note that if you had done exec twm, the shell would have replaced itself with twm which means that it would not be able to run the other commands in the script. This is why you instead start twm as a background process (with & at the end). The sleep is there to allow twm to start up properly before starting the terminal. I don't think this is strictly necessary. In fact, if you don't need window decorations or to be able to move windows around or resize them, there is no need to even run twm or any other window manager (at least not for running a full screen xterm).



        In your second example, you use



        exec WINDOWING=x11 /usr/bin/kodi -geometry +0+0


        Now, the exec command can't be used to set environment variables like that. Instead, you would set and export the WINDOWING variable before invoking kodi:



        export WINDOWING=x11
        exec /usr/bin/kodi -geometry +0+0






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 5 at 8:04

























        answered Mar 4 at 7:38









        KusalanandaKusalananda

        139k17259429




        139k17259429



























            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.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f504188%2fmysteries-of-xinitrc-what-can-and-cannot-be-there%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

            How to check contact read email or not when send email to Individual?

            Displaying single band from multi-band raster using QGIS

            How many registers does an x86_64 CPU actually have?