Starting multiple Screen windows from shell script uses wrong configuration

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











up vote
1
down vote

favorite
1












When running Screen, I can use Ctrl+ac to create a new window and run vim in each window. Also from Screen, I can run the command screen vim multiple times to open new windows with vim already running. These work as expected. However...



If I put the command multiple times in a script, such as:



#!/bin/bash
screen vim
screen vim
screen vim


...and run that script from within Screen, the first command will run as expected, but the second and following ones will not.



Things I have noticed are:



  1. Window 2 and beyond does not have stty -ixon applied, which I have set in .bashrc

  2. If I don't have colorscheme set explicitly in .vimrc, it will use one scheme in window 1 and another in all following windows

  3. Sometimes a command will be skipped, i.e., sometimes only two new windows will be opened where the script was set to open three

  4. If I do a :windowlist, window 2 and following will not have the login flag set (running screen vim directly will set this flag), e.g.,


Num Name Flags
0 bash $
1 vim $ <-- running the script from window 0 opened 1..3 (no flag on 2 or 3)
2 vim
3 vim
4 vim $ <-- manually running `screen vim` from window 0 always sets the flag


  1. Using Ctrl+aL on a window that's not logged in will return the message This window is not logged in and the flag will not be set. Pressing the keys again will then toggle between logged in and out (though stty -ixon etc' will still not be applied)

  2. Running htop will show all instances of vim (including ones that are not logged in) are running under my user.

Why does manually opening multiple windows apply my settings correctly, but using a script doesn't?



I am new to Linux and not sure if I'm doing something silly here.







share|improve this question
























    up vote
    1
    down vote

    favorite
    1












    When running Screen, I can use Ctrl+ac to create a new window and run vim in each window. Also from Screen, I can run the command screen vim multiple times to open new windows with vim already running. These work as expected. However...



    If I put the command multiple times in a script, such as:



    #!/bin/bash
    screen vim
    screen vim
    screen vim


    ...and run that script from within Screen, the first command will run as expected, but the second and following ones will not.



    Things I have noticed are:



    1. Window 2 and beyond does not have stty -ixon applied, which I have set in .bashrc

    2. If I don't have colorscheme set explicitly in .vimrc, it will use one scheme in window 1 and another in all following windows

    3. Sometimes a command will be skipped, i.e., sometimes only two new windows will be opened where the script was set to open three

    4. If I do a :windowlist, window 2 and following will not have the login flag set (running screen vim directly will set this flag), e.g.,


    Num Name Flags
    0 bash $
    1 vim $ <-- running the script from window 0 opened 1..3 (no flag on 2 or 3)
    2 vim
    3 vim
    4 vim $ <-- manually running `screen vim` from window 0 always sets the flag


    1. Using Ctrl+aL on a window that's not logged in will return the message This window is not logged in and the flag will not be set. Pressing the keys again will then toggle between logged in and out (though stty -ixon etc' will still not be applied)

    2. Running htop will show all instances of vim (including ones that are not logged in) are running under my user.

    Why does manually opening multiple windows apply my settings correctly, but using a script doesn't?



    I am new to Linux and not sure if I'm doing something silly here.







    share|improve this question






















      up vote
      1
      down vote

      favorite
      1









      up vote
      1
      down vote

      favorite
      1






      1





      When running Screen, I can use Ctrl+ac to create a new window and run vim in each window. Also from Screen, I can run the command screen vim multiple times to open new windows with vim already running. These work as expected. However...



      If I put the command multiple times in a script, such as:



      #!/bin/bash
      screen vim
      screen vim
      screen vim


      ...and run that script from within Screen, the first command will run as expected, but the second and following ones will not.



      Things I have noticed are:



      1. Window 2 and beyond does not have stty -ixon applied, which I have set in .bashrc

      2. If I don't have colorscheme set explicitly in .vimrc, it will use one scheme in window 1 and another in all following windows

      3. Sometimes a command will be skipped, i.e., sometimes only two new windows will be opened where the script was set to open three

      4. If I do a :windowlist, window 2 and following will not have the login flag set (running screen vim directly will set this flag), e.g.,


      Num Name Flags
      0 bash $
      1 vim $ <-- running the script from window 0 opened 1..3 (no flag on 2 or 3)
      2 vim
      3 vim
      4 vim $ <-- manually running `screen vim` from window 0 always sets the flag


      1. Using Ctrl+aL on a window that's not logged in will return the message This window is not logged in and the flag will not be set. Pressing the keys again will then toggle between logged in and out (though stty -ixon etc' will still not be applied)

      2. Running htop will show all instances of vim (including ones that are not logged in) are running under my user.

      Why does manually opening multiple windows apply my settings correctly, but using a script doesn't?



      I am new to Linux and not sure if I'm doing something silly here.







      share|improve this question












      When running Screen, I can use Ctrl+ac to create a new window and run vim in each window. Also from Screen, I can run the command screen vim multiple times to open new windows with vim already running. These work as expected. However...



      If I put the command multiple times in a script, such as:



      #!/bin/bash
      screen vim
      screen vim
      screen vim


      ...and run that script from within Screen, the first command will run as expected, but the second and following ones will not.



      Things I have noticed are:



      1. Window 2 and beyond does not have stty -ixon applied, which I have set in .bashrc

      2. If I don't have colorscheme set explicitly in .vimrc, it will use one scheme in window 1 and another in all following windows

      3. Sometimes a command will be skipped, i.e., sometimes only two new windows will be opened where the script was set to open three

      4. If I do a :windowlist, window 2 and following will not have the login flag set (running screen vim directly will set this flag), e.g.,


      Num Name Flags
      0 bash $
      1 vim $ <-- running the script from window 0 opened 1..3 (no flag on 2 or 3)
      2 vim
      3 vim
      4 vim $ <-- manually running `screen vim` from window 0 always sets the flag


      1. Using Ctrl+aL on a window that's not logged in will return the message This window is not logged in and the flag will not be set. Pressing the keys again will then toggle between logged in and out (though stty -ixon etc' will still not be applied)

      2. Running htop will show all instances of vim (including ones that are not logged in) are running under my user.

      Why does manually opening multiple windows apply my settings correctly, but using a script doesn't?



      I am new to Linux and not sure if I'm doing something silly here.









      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 14 at 7:11









      Eliott

      63




      63




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          I believe I found that the problem is caused by the script running all commands (except the first) in the background. I can force the first command to have the same problem by forking it with &.



          After not being able to find a way to have the script run each command in the foreground, one-after-the-other, I have found an alternative solution...



          I can put all the commands in a custom screenrc file (e.g., my_screenrc) as such:



          # Import default screenrc
          source $HOME/.screenrc

          # Run screen-specific commands (not bash ones)
          screen # Run bash in window 0
          screen vim # Run vim in windows 1 through 3 (with correct settings)
          screen vim
          screen vim


          I can then run this from bash with:



          screen -c my_screenrc





          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',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            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%2f416979%2fstarting-multiple-screen-windows-from-shell-script-uses-wrong-configuration%23new-answer', 'question_page');

            );

            Post as a guest






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote



            accepted










            I believe I found that the problem is caused by the script running all commands (except the first) in the background. I can force the first command to have the same problem by forking it with &.



            After not being able to find a way to have the script run each command in the foreground, one-after-the-other, I have found an alternative solution...



            I can put all the commands in a custom screenrc file (e.g., my_screenrc) as such:



            # Import default screenrc
            source $HOME/.screenrc

            # Run screen-specific commands (not bash ones)
            screen # Run bash in window 0
            screen vim # Run vim in windows 1 through 3 (with correct settings)
            screen vim
            screen vim


            I can then run this from bash with:



            screen -c my_screenrc





            share|improve this answer
























              up vote
              0
              down vote



              accepted










              I believe I found that the problem is caused by the script running all commands (except the first) in the background. I can force the first command to have the same problem by forking it with &.



              After not being able to find a way to have the script run each command in the foreground, one-after-the-other, I have found an alternative solution...



              I can put all the commands in a custom screenrc file (e.g., my_screenrc) as such:



              # Import default screenrc
              source $HOME/.screenrc

              # Run screen-specific commands (not bash ones)
              screen # Run bash in window 0
              screen vim # Run vim in windows 1 through 3 (with correct settings)
              screen vim
              screen vim


              I can then run this from bash with:



              screen -c my_screenrc





              share|improve this answer






















                up vote
                0
                down vote



                accepted







                up vote
                0
                down vote



                accepted






                I believe I found that the problem is caused by the script running all commands (except the first) in the background. I can force the first command to have the same problem by forking it with &.



                After not being able to find a way to have the script run each command in the foreground, one-after-the-other, I have found an alternative solution...



                I can put all the commands in a custom screenrc file (e.g., my_screenrc) as such:



                # Import default screenrc
                source $HOME/.screenrc

                # Run screen-specific commands (not bash ones)
                screen # Run bash in window 0
                screen vim # Run vim in windows 1 through 3 (with correct settings)
                screen vim
                screen vim


                I can then run this from bash with:



                screen -c my_screenrc





                share|improve this answer












                I believe I found that the problem is caused by the script running all commands (except the first) in the background. I can force the first command to have the same problem by forking it with &.



                After not being able to find a way to have the script run each command in the foreground, one-after-the-other, I have found an alternative solution...



                I can put all the commands in a custom screenrc file (e.g., my_screenrc) as such:



                # Import default screenrc
                source $HOME/.screenrc

                # Run screen-specific commands (not bash ones)
                screen # Run bash in window 0
                screen vim # Run vim in windows 1 through 3 (with correct settings)
                screen vim
                screen vim


                I can then run this from bash with:



                screen -c my_screenrc






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 26 at 5:24









                Eliott

                63




                63






















                     

                    draft saved


                    draft discarded


























                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f416979%2fstarting-multiple-screen-windows-from-shell-script-uses-wrong-configuration%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    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?