Pasting multiple lines so that they consistently executePrevent users from killing processes that they ownClipboard utility to paste back multiple lines one by oneShould scripts that require sudo fail if they don't have it, or use sudo and prompt?Multiple lines of input for multiple variablesHow to execute multiple commands remotely on few servers?Bash commands get truncated when pasting multiple commands to terminalExecute multiple command through SSH using sudoPasting multiple commands into terminal stops at user inputPrint result in multiple linesWrite a string to the file that only root can access when execute the php file

Escape a backup date in a file name

What is the intuitive meaning of having a linear relationship between the logs of two variables?

A particular customize with green line and letters for subfloat

How do we know the LHC results are robust?

Class Action - which options I have?

Is the destination of a commercial flight important for the pilot?

What Brexit proposals are on the table in the indicative votes on the 27th of March 2019?

Failed to fetch jessie backports repository

India just shot down a satellite from the ground. At what altitude range is the resulting debris field?

Short story about space worker geeks who zone out by 'listening' to radiation from stars

Is there a problem with hiding "forgot password" until it's needed?

What happens if you roll doubles 3 times then land on "Go to jail?"

Go Pregnant or Go Home

How to write papers efficiently when English isn't my first language?

What is the difference between "behavior" and "behaviour"?

Integer addition + constant, is it a group?

Method to test if a number is a perfect power?

Increase performance creating Mandelbrot set in python

What is the opposite of 'gravitas'?

How can we prove that any integral in the set of non-elementary integrals cannot be expressed in the form of elementary functions?

Avoiding estate tax by giving multiple gifts

Why not increase contact surface when reentering the atmosphere?

Trouble understanding the speech of overseas colleagues

How can I get through very long and very dry, but also very useful technical documents when learning a new tool?



Pasting multiple lines so that they consistently execute


Prevent users from killing processes that they ownClipboard utility to paste back multiple lines one by oneShould scripts that require sudo fail if they don't have it, or use sudo and prompt?Multiple lines of input for multiple variablesHow to execute multiple commands remotely on few servers?Bash commands get truncated when pasting multiple commands to terminalExecute multiple command through SSH using sudoPasting multiple commands into terminal stops at user inputPrint result in multiple linesWrite a string to the file that only root can access when execute the php file













1















Here's an example of a very simple code snippet that I'd like to paste to my terminal in a way that everything is executed.



sudo apt update
sudo apt upgrade


sudo apt -y install build-essential
sudo apt -y install git
sudo apt -y install libxml2-dev # required for some tools using xml files

sudo apt autoremove


Unfortunately, what happens if build-essential wasn't installed beforehand is that it only runs until sudo apt -y install build-essential. The subsequent lines are skipped. The same is true if git wasn't installed: It'll run until the git line, then skip the rest.



What's the reason for this happening, and is there a way to fix this problem without having to create a script file and running it via bash?










share|improve this question









New contributor




Michael is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 1





    Trying to understand... If the build-essential were to fail, would you want to continue executing the other items?

    – roaima
    yesterday












  • Also, since you're (probably) running these commands via bash, is there a particular problem with creating a script and running that?

    – roaima
    yesterday











  • Basically, I'm just trying to understand what it is exactly that prevents this snippet from being fully executed (line by line) by pasting it into the Unix terminal.

    – Michael
    yesterday












  • I have a collection of Unix shell snippets and I need to have a basic understanding of when pasting snippets into the terminal works, and when it doesn't.

    – Michael
    yesterday











  • does apt install build-essential prompt for input during the installation?

    – Jeff Schaller
    yesterday















1















Here's an example of a very simple code snippet that I'd like to paste to my terminal in a way that everything is executed.



sudo apt update
sudo apt upgrade


sudo apt -y install build-essential
sudo apt -y install git
sudo apt -y install libxml2-dev # required for some tools using xml files

sudo apt autoremove


Unfortunately, what happens if build-essential wasn't installed beforehand is that it only runs until sudo apt -y install build-essential. The subsequent lines are skipped. The same is true if git wasn't installed: It'll run until the git line, then skip the rest.



What's the reason for this happening, and is there a way to fix this problem without having to create a script file and running it via bash?










share|improve this question









New contributor




Michael is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 1





    Trying to understand... If the build-essential were to fail, would you want to continue executing the other items?

    – roaima
    yesterday












  • Also, since you're (probably) running these commands via bash, is there a particular problem with creating a script and running that?

    – roaima
    yesterday











  • Basically, I'm just trying to understand what it is exactly that prevents this snippet from being fully executed (line by line) by pasting it into the Unix terminal.

    – Michael
    yesterday












  • I have a collection of Unix shell snippets and I need to have a basic understanding of when pasting snippets into the terminal works, and when it doesn't.

    – Michael
    yesterday











  • does apt install build-essential prompt for input during the installation?

    – Jeff Schaller
    yesterday













1












1








1








Here's an example of a very simple code snippet that I'd like to paste to my terminal in a way that everything is executed.



sudo apt update
sudo apt upgrade


sudo apt -y install build-essential
sudo apt -y install git
sudo apt -y install libxml2-dev # required for some tools using xml files

sudo apt autoremove


Unfortunately, what happens if build-essential wasn't installed beforehand is that it only runs until sudo apt -y install build-essential. The subsequent lines are skipped. The same is true if git wasn't installed: It'll run until the git line, then skip the rest.



What's the reason for this happening, and is there a way to fix this problem without having to create a script file and running it via bash?










share|improve this question









New contributor




Michael is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












Here's an example of a very simple code snippet that I'd like to paste to my terminal in a way that everything is executed.



sudo apt update
sudo apt upgrade


sudo apt -y install build-essential
sudo apt -y install git
sudo apt -y install libxml2-dev # required for some tools using xml files

sudo apt autoremove


Unfortunately, what happens if build-essential wasn't installed beforehand is that it only runs until sudo apt -y install build-essential. The subsequent lines are skipped. The same is true if git wasn't installed: It'll run until the git line, then skip the rest.



What's the reason for this happening, and is there a way to fix this problem without having to create a script file and running it via bash?







bash sudo clipboard






share|improve this question









New contributor




Michael is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Michael is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited yesterday









0xSheepdog

1,6041924




1,6041924






New contributor




Michael is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked yesterday









MichaelMichael

83




83




New contributor




Michael is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Michael is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Michael is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







  • 1





    Trying to understand... If the build-essential were to fail, would you want to continue executing the other items?

    – roaima
    yesterday












  • Also, since you're (probably) running these commands via bash, is there a particular problem with creating a script and running that?

    – roaima
    yesterday











  • Basically, I'm just trying to understand what it is exactly that prevents this snippet from being fully executed (line by line) by pasting it into the Unix terminal.

    – Michael
    yesterday












  • I have a collection of Unix shell snippets and I need to have a basic understanding of when pasting snippets into the terminal works, and when it doesn't.

    – Michael
    yesterday











  • does apt install build-essential prompt for input during the installation?

    – Jeff Schaller
    yesterday












  • 1





    Trying to understand... If the build-essential were to fail, would you want to continue executing the other items?

    – roaima
    yesterday












  • Also, since you're (probably) running these commands via bash, is there a particular problem with creating a script and running that?

    – roaima
    yesterday











  • Basically, I'm just trying to understand what it is exactly that prevents this snippet from being fully executed (line by line) by pasting it into the Unix terminal.

    – Michael
    yesterday












  • I have a collection of Unix shell snippets and I need to have a basic understanding of when pasting snippets into the terminal works, and when it doesn't.

    – Michael
    yesterday











  • does apt install build-essential prompt for input during the installation?

    – Jeff Schaller
    yesterday







1




1





Trying to understand... If the build-essential were to fail, would you want to continue executing the other items?

– roaima
yesterday






Trying to understand... If the build-essential were to fail, would you want to continue executing the other items?

– roaima
yesterday














Also, since you're (probably) running these commands via bash, is there a particular problem with creating a script and running that?

– roaima
yesterday





Also, since you're (probably) running these commands via bash, is there a particular problem with creating a script and running that?

– roaima
yesterday













Basically, I'm just trying to understand what it is exactly that prevents this snippet from being fully executed (line by line) by pasting it into the Unix terminal.

– Michael
yesterday






Basically, I'm just trying to understand what it is exactly that prevents this snippet from being fully executed (line by line) by pasting it into the Unix terminal.

– Michael
yesterday














I have a collection of Unix shell snippets and I need to have a basic understanding of when pasting snippets into the terminal works, and when it doesn't.

– Michael
yesterday





I have a collection of Unix shell snippets and I need to have a basic understanding of when pasting snippets into the terminal works, and when it doesn't.

– Michael
yesterday













does apt install build-essential prompt for input during the installation?

– Jeff Schaller
yesterday





does apt install build-essential prompt for input during the installation?

– Jeff Schaller
yesterday










2 Answers
2






active

oldest

votes


















2














Assuming you are still within sudo's credential cache timeout (if you are unsure, just refresh it with sudo -v before running the snippet), that problem happens because apt(-get) is a very rich console application and thus consumes stdin even when it asks you nothing because of the -y.



You can work around that by running the whole snippet in a subshell:



At the prompt, start by typing a ( then paste the snippet then type the closing ) and press return



It should go.



Notice how the snippet is not executed as soon as you paste it. It rather gets “queued” on the command line, waiting for the closing parentheses.



(PS: depending on your system you may need to use apt-get autoremove in place of apt autoremove, and you may also need to use -y on update and upgrade too)






share|improve this answer

























  • Awesome, that did it! So basically sudo and apt are complex commands that have a tendency to eat up input. Gotcha. Just one comment: apt autoremove exists and works. Also, an alternative workaround I found is to concatenate the commands via && (ensuring the next line always is only executed if the previous succeeded) and to either write all commands on a single line, or to use the escape character .

    – Michael
    yesterday












  • ugh.. It's really about time to update my system then.. apt autoremove does not work for me..! :-(

    – LL3
    yesterday











  • @Michael Of course those ways and a few others work too, but you wanted to just copy&paste it ;-)

    – LL3
    yesterday


















1














If there is sufficient time between the sudo apt upgrade command and the sudo apt install -y build-essentials command, then SUDO will prompt for your password again.



Because you are pasting text into the console, the next line(s) will be accepted as STDIN to the SUDO prompt for a password. If the line does not match your password, authentication will fail and the build-essentials line will not be executed.






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
    );



    );






    Michael is a new contributor. Be nice, and check out our Code of Conduct.









    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f508768%2fpasting-multiple-lines-so-that-they-consistently-execute%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    Assuming you are still within sudo's credential cache timeout (if you are unsure, just refresh it with sudo -v before running the snippet), that problem happens because apt(-get) is a very rich console application and thus consumes stdin even when it asks you nothing because of the -y.



    You can work around that by running the whole snippet in a subshell:



    At the prompt, start by typing a ( then paste the snippet then type the closing ) and press return



    It should go.



    Notice how the snippet is not executed as soon as you paste it. It rather gets “queued” on the command line, waiting for the closing parentheses.



    (PS: depending on your system you may need to use apt-get autoremove in place of apt autoremove, and you may also need to use -y on update and upgrade too)






    share|improve this answer

























    • Awesome, that did it! So basically sudo and apt are complex commands that have a tendency to eat up input. Gotcha. Just one comment: apt autoremove exists and works. Also, an alternative workaround I found is to concatenate the commands via && (ensuring the next line always is only executed if the previous succeeded) and to either write all commands on a single line, or to use the escape character .

      – Michael
      yesterday












    • ugh.. It's really about time to update my system then.. apt autoremove does not work for me..! :-(

      – LL3
      yesterday











    • @Michael Of course those ways and a few others work too, but you wanted to just copy&paste it ;-)

      – LL3
      yesterday















    2














    Assuming you are still within sudo's credential cache timeout (if you are unsure, just refresh it with sudo -v before running the snippet), that problem happens because apt(-get) is a very rich console application and thus consumes stdin even when it asks you nothing because of the -y.



    You can work around that by running the whole snippet in a subshell:



    At the prompt, start by typing a ( then paste the snippet then type the closing ) and press return



    It should go.



    Notice how the snippet is not executed as soon as you paste it. It rather gets “queued” on the command line, waiting for the closing parentheses.



    (PS: depending on your system you may need to use apt-get autoremove in place of apt autoremove, and you may also need to use -y on update and upgrade too)






    share|improve this answer

























    • Awesome, that did it! So basically sudo and apt are complex commands that have a tendency to eat up input. Gotcha. Just one comment: apt autoremove exists and works. Also, an alternative workaround I found is to concatenate the commands via && (ensuring the next line always is only executed if the previous succeeded) and to either write all commands on a single line, or to use the escape character .

      – Michael
      yesterday












    • ugh.. It's really about time to update my system then.. apt autoremove does not work for me..! :-(

      – LL3
      yesterday











    • @Michael Of course those ways and a few others work too, but you wanted to just copy&paste it ;-)

      – LL3
      yesterday













    2












    2








    2







    Assuming you are still within sudo's credential cache timeout (if you are unsure, just refresh it with sudo -v before running the snippet), that problem happens because apt(-get) is a very rich console application and thus consumes stdin even when it asks you nothing because of the -y.



    You can work around that by running the whole snippet in a subshell:



    At the prompt, start by typing a ( then paste the snippet then type the closing ) and press return



    It should go.



    Notice how the snippet is not executed as soon as you paste it. It rather gets “queued” on the command line, waiting for the closing parentheses.



    (PS: depending on your system you may need to use apt-get autoremove in place of apt autoremove, and you may also need to use -y on update and upgrade too)






    share|improve this answer















    Assuming you are still within sudo's credential cache timeout (if you are unsure, just refresh it with sudo -v before running the snippet), that problem happens because apt(-get) is a very rich console application and thus consumes stdin even when it asks you nothing because of the -y.



    You can work around that by running the whole snippet in a subshell:



    At the prompt, start by typing a ( then paste the snippet then type the closing ) and press return



    It should go.



    Notice how the snippet is not executed as soon as you paste it. It rather gets “queued” on the command line, waiting for the closing parentheses.



    (PS: depending on your system you may need to use apt-get autoremove in place of apt autoremove, and you may also need to use -y on update and upgrade too)







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited yesterday

























    answered yesterday









    LL3LL3

    1565




    1565












    • Awesome, that did it! So basically sudo and apt are complex commands that have a tendency to eat up input. Gotcha. Just one comment: apt autoremove exists and works. Also, an alternative workaround I found is to concatenate the commands via && (ensuring the next line always is only executed if the previous succeeded) and to either write all commands on a single line, or to use the escape character .

      – Michael
      yesterday












    • ugh.. It's really about time to update my system then.. apt autoremove does not work for me..! :-(

      – LL3
      yesterday











    • @Michael Of course those ways and a few others work too, but you wanted to just copy&paste it ;-)

      – LL3
      yesterday

















    • Awesome, that did it! So basically sudo and apt are complex commands that have a tendency to eat up input. Gotcha. Just one comment: apt autoremove exists and works. Also, an alternative workaround I found is to concatenate the commands via && (ensuring the next line always is only executed if the previous succeeded) and to either write all commands on a single line, or to use the escape character .

      – Michael
      yesterday












    • ugh.. It's really about time to update my system then.. apt autoremove does not work for me..! :-(

      – LL3
      yesterday











    • @Michael Of course those ways and a few others work too, but you wanted to just copy&paste it ;-)

      – LL3
      yesterday
















    Awesome, that did it! So basically sudo and apt are complex commands that have a tendency to eat up input. Gotcha. Just one comment: apt autoremove exists and works. Also, an alternative workaround I found is to concatenate the commands via && (ensuring the next line always is only executed if the previous succeeded) and to either write all commands on a single line, or to use the escape character .

    – Michael
    yesterday






    Awesome, that did it! So basically sudo and apt are complex commands that have a tendency to eat up input. Gotcha. Just one comment: apt autoremove exists and works. Also, an alternative workaround I found is to concatenate the commands via && (ensuring the next line always is only executed if the previous succeeded) and to either write all commands on a single line, or to use the escape character .

    – Michael
    yesterday














    ugh.. It's really about time to update my system then.. apt autoremove does not work for me..! :-(

    – LL3
    yesterday





    ugh.. It's really about time to update my system then.. apt autoremove does not work for me..! :-(

    – LL3
    yesterday













    @Michael Of course those ways and a few others work too, but you wanted to just copy&paste it ;-)

    – LL3
    yesterday





    @Michael Of course those ways and a few others work too, but you wanted to just copy&paste it ;-)

    – LL3
    yesterday













    1














    If there is sufficient time between the sudo apt upgrade command and the sudo apt install -y build-essentials command, then SUDO will prompt for your password again.



    Because you are pasting text into the console, the next line(s) will be accepted as STDIN to the SUDO prompt for a password. If the line does not match your password, authentication will fail and the build-essentials line will not be executed.






    share|improve this answer



























      1














      If there is sufficient time between the sudo apt upgrade command and the sudo apt install -y build-essentials command, then SUDO will prompt for your password again.



      Because you are pasting text into the console, the next line(s) will be accepted as STDIN to the SUDO prompt for a password. If the line does not match your password, authentication will fail and the build-essentials line will not be executed.






      share|improve this answer

























        1












        1








        1







        If there is sufficient time between the sudo apt upgrade command and the sudo apt install -y build-essentials command, then SUDO will prompt for your password again.



        Because you are pasting text into the console, the next line(s) will be accepted as STDIN to the SUDO prompt for a password. If the line does not match your password, authentication will fail and the build-essentials line will not be executed.






        share|improve this answer













        If there is sufficient time between the sudo apt upgrade command and the sudo apt install -y build-essentials command, then SUDO will prompt for your password again.



        Because you are pasting text into the console, the next line(s) will be accepted as STDIN to the SUDO prompt for a password. If the line does not match your password, authentication will fail and the build-essentials line will not be executed.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered yesterday









        0xSheepdog0xSheepdog

        1,6041924




        1,6041924




















            Michael is a new contributor. Be nice, and check out our Code of Conduct.









            draft saved

            draft discarded


















            Michael is a new contributor. Be nice, and check out our Code of Conduct.












            Michael is a new contributor. Be nice, and check out our Code of Conduct.











            Michael is a new contributor. Be nice, and check out our Code of Conduct.














            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%2f508768%2fpasting-multiple-lines-so-that-they-consistently-execute%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







            -bash, clipboard, sudo

            Popular posts from this blog

            Frič See also Navigation menuinternal link

            Identify plant with long narrow paired leaves and reddish stems Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?What is this plant with long sharp leaves? Is it a weed?What is this 3ft high, stalky plant, with mid sized narrow leaves?What is this young shrub with opposite ovate, crenate leaves and reddish stems?What is this plant with large broad serrated leaves?Identify this upright branching weed with long leaves and reddish stemsPlease help me identify this bulbous plant with long, broad leaves and white flowersWhat is this small annual with narrow gray/green leaves and rust colored daisy-type flowers?What is this chilli plant?Does anyone know what type of chilli plant this is?Help identify this plant

            fontconfig warning: “/etc/fonts/fonts.conf”, line 100: unknown “element blank” The 2019 Stack Overflow Developer Survey Results Are In“tar: unrecognized option --warning” during 'apt-get install'How to fix Fontconfig errorHow do I figure out which font file is chosen for a system generic font alias?Why are some apt-get-installed fonts being ignored by fc-list, xfontsel, etc?Reload settings in /etc/fonts/conf.dTaking 30 seconds longer to boot after upgrade from jessie to stretchHow to match multiple font names with a single <match> element?Adding a custom font to fontconfigRemoving fonts from fontconfig <match> resultsBroken fonts after upgrading Firefox ESR to latest Firefox