Where is my pasted input going?

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











up vote
1
down vote

favorite












I am copying and pasting sequences of shell commands into my terminal emulator, and I am confused by the behaviour.



  • When I paste the single line ssh user@remote "echo foo"; echo baz the computer does what I expect. It runs the SSH command and then echoes something after I have finished my SSH session.

  • When I paste the same thing as a multiple-line command, however, this does not happen.
    ssh user@remote "echo foo"
    echo baz
    I still get the SSH session, but the echo baz completely disappears. No command is run.

  • This seems to be something to do with SSH, at least. Because replacing SSH with something else yields the behaviour that I was actually expecting.
    Both commands run when I paste this, for example:
    echo foo
    echo baz


So what is happening? Where is the pasted input going? Why is the echo command not executed by anything? How is this related to SSH?



(By the way: I know of Ctrl+X, Ctrl+E method, but sometimes, especially when using terminal emulators on Windows, this won't work out of the box.)







share|improve this question





















  • The conclusion that you have jumped to, upon which you have then based the question, is wrong.
    – JdeBP
    Jun 25 at 16:52










  • Do you mean specifically, that I'm referring to ssh as the source of this behavior? It might be one of the cases, and since I didn't search for any other, I've decided to leave it as an example. Or do you refer to "copy-pasting" instead of "evaluating pasted"?
    – mjktfw
    Jun 25 at 17:05











  • You've jumped to the conclusion that stuff is not being pasted, and then asked why pasting breaks. It is not actually the case in the first place that the input is not being pasted. So this question is based upon a false assumption from the title onwards. Where is this pasted input going? is by far a better question.
    – JdeBP
    Jun 25 at 17:15










  • There you go. The answer to this is actually fairly straightforward, Let's see whether anyone answers it.
    – JdeBP
    Jun 25 at 17:30














up vote
1
down vote

favorite












I am copying and pasting sequences of shell commands into my terminal emulator, and I am confused by the behaviour.



  • When I paste the single line ssh user@remote "echo foo"; echo baz the computer does what I expect. It runs the SSH command and then echoes something after I have finished my SSH session.

  • When I paste the same thing as a multiple-line command, however, this does not happen.
    ssh user@remote "echo foo"
    echo baz
    I still get the SSH session, but the echo baz completely disappears. No command is run.

  • This seems to be something to do with SSH, at least. Because replacing SSH with something else yields the behaviour that I was actually expecting.
    Both commands run when I paste this, for example:
    echo foo
    echo baz


So what is happening? Where is the pasted input going? Why is the echo command not executed by anything? How is this related to SSH?



(By the way: I know of Ctrl+X, Ctrl+E method, but sometimes, especially when using terminal emulators on Windows, this won't work out of the box.)







share|improve this question





















  • The conclusion that you have jumped to, upon which you have then based the question, is wrong.
    – JdeBP
    Jun 25 at 16:52










  • Do you mean specifically, that I'm referring to ssh as the source of this behavior? It might be one of the cases, and since I didn't search for any other, I've decided to leave it as an example. Or do you refer to "copy-pasting" instead of "evaluating pasted"?
    – mjktfw
    Jun 25 at 17:05











  • You've jumped to the conclusion that stuff is not being pasted, and then asked why pasting breaks. It is not actually the case in the first place that the input is not being pasted. So this question is based upon a false assumption from the title onwards. Where is this pasted input going? is by far a better question.
    – JdeBP
    Jun 25 at 17:15










  • There you go. The answer to this is actually fairly straightforward, Let's see whether anyone answers it.
    – JdeBP
    Jun 25 at 17:30












up vote
1
down vote

favorite









up vote
1
down vote

favorite











I am copying and pasting sequences of shell commands into my terminal emulator, and I am confused by the behaviour.



  • When I paste the single line ssh user@remote "echo foo"; echo baz the computer does what I expect. It runs the SSH command and then echoes something after I have finished my SSH session.

  • When I paste the same thing as a multiple-line command, however, this does not happen.
    ssh user@remote "echo foo"
    echo baz
    I still get the SSH session, but the echo baz completely disappears. No command is run.

  • This seems to be something to do with SSH, at least. Because replacing SSH with something else yields the behaviour that I was actually expecting.
    Both commands run when I paste this, for example:
    echo foo
    echo baz


So what is happening? Where is the pasted input going? Why is the echo command not executed by anything? How is this related to SSH?



(By the way: I know of Ctrl+X, Ctrl+E method, but sometimes, especially when using terminal emulators on Windows, this won't work out of the box.)







share|improve this question













I am copying and pasting sequences of shell commands into my terminal emulator, and I am confused by the behaviour.



  • When I paste the single line ssh user@remote "echo foo"; echo baz the computer does what I expect. It runs the SSH command and then echoes something after I have finished my SSH session.

  • When I paste the same thing as a multiple-line command, however, this does not happen.
    ssh user@remote "echo foo"
    echo baz
    I still get the SSH session, but the echo baz completely disappears. No command is run.

  • This seems to be something to do with SSH, at least. Because replacing SSH with something else yields the behaviour that I was actually expecting.
    Both commands run when I paste this, for example:
    echo foo
    echo baz


So what is happening? Where is the pasted input going? Why is the echo command not executed by anything? How is this related to SSH?



(By the way: I know of Ctrl+X, Ctrl+E method, but sometimes, especially when using terminal emulators on Windows, this won't work out of the box.)









share|improve this question












share|improve this question




share|improve this question








edited Jun 25 at 17:29









JdeBP

27.9k459133




27.9k459133









asked Jun 25 at 14:23









mjktfw

142




142











  • The conclusion that you have jumped to, upon which you have then based the question, is wrong.
    – JdeBP
    Jun 25 at 16:52










  • Do you mean specifically, that I'm referring to ssh as the source of this behavior? It might be one of the cases, and since I didn't search for any other, I've decided to leave it as an example. Or do you refer to "copy-pasting" instead of "evaluating pasted"?
    – mjktfw
    Jun 25 at 17:05











  • You've jumped to the conclusion that stuff is not being pasted, and then asked why pasting breaks. It is not actually the case in the first place that the input is not being pasted. So this question is based upon a false assumption from the title onwards. Where is this pasted input going? is by far a better question.
    – JdeBP
    Jun 25 at 17:15










  • There you go. The answer to this is actually fairly straightforward, Let's see whether anyone answers it.
    – JdeBP
    Jun 25 at 17:30
















  • The conclusion that you have jumped to, upon which you have then based the question, is wrong.
    – JdeBP
    Jun 25 at 16:52










  • Do you mean specifically, that I'm referring to ssh as the source of this behavior? It might be one of the cases, and since I didn't search for any other, I've decided to leave it as an example. Or do you refer to "copy-pasting" instead of "evaluating pasted"?
    – mjktfw
    Jun 25 at 17:05











  • You've jumped to the conclusion that stuff is not being pasted, and then asked why pasting breaks. It is not actually the case in the first place that the input is not being pasted. So this question is based upon a false assumption from the title onwards. Where is this pasted input going? is by far a better question.
    – JdeBP
    Jun 25 at 17:15










  • There you go. The answer to this is actually fairly straightforward, Let's see whether anyone answers it.
    – JdeBP
    Jun 25 at 17:30















The conclusion that you have jumped to, upon which you have then based the question, is wrong.
– JdeBP
Jun 25 at 16:52




The conclusion that you have jumped to, upon which you have then based the question, is wrong.
– JdeBP
Jun 25 at 16:52












Do you mean specifically, that I'm referring to ssh as the source of this behavior? It might be one of the cases, and since I didn't search for any other, I've decided to leave it as an example. Or do you refer to "copy-pasting" instead of "evaluating pasted"?
– mjktfw
Jun 25 at 17:05





Do you mean specifically, that I'm referring to ssh as the source of this behavior? It might be one of the cases, and since I didn't search for any other, I've decided to leave it as an example. Or do you refer to "copy-pasting" instead of "evaluating pasted"?
– mjktfw
Jun 25 at 17:05













You've jumped to the conclusion that stuff is not being pasted, and then asked why pasting breaks. It is not actually the case in the first place that the input is not being pasted. So this question is based upon a false assumption from the title onwards. Where is this pasted input going? is by far a better question.
– JdeBP
Jun 25 at 17:15




You've jumped to the conclusion that stuff is not being pasted, and then asked why pasting breaks. It is not actually the case in the first place that the input is not being pasted. So this question is based upon a false assumption from the title onwards. Where is this pasted input going? is by far a better question.
– JdeBP
Jun 25 at 17:15












There you go. The answer to this is actually fairly straightforward, Let's see whether anyone answers it.
– JdeBP
Jun 25 at 17:30




There you go. The answer to this is actually fairly straightforward, Let's see whether anyone answers it.
– JdeBP
Jun 25 at 17:30










1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










Try pasting this:



ssh user@host 'read foo; echo ">>$foo<<"'
echo bar


You will see >>echo bar<< as output from the echo on the server.



This means that ssh will eat the pasted data on its standard input, as if you had done



echo 'echo bar' | ssh user@host 'read foo; echo ">>$foo<<"'


The solution to this, apart from never pasting shell commands into the terminal to run them, is to use ssh -n, which will redirect /dev/null into ssh:



ssh -n user@host 'echo foo'
echo bar



Unfortunately I don't know the mechanics of pasting, so I can't say anything clever about why the pasted data ends up on the standard input stream of ssh, but I'm guessing it has to do with the stream being inherited from the interactive shell (which reads commands from standard input).




Using ssh -n is also the solution (or at least a solution) to the issue of



while read something; do
ssh user@host 'somecommand'
done <inputfile


Here, the loop will only run once since ssh eats the data from inputfile.






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%2f451776%2fwhere-is-my-pasted-input-going%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
    1
    down vote



    accepted










    Try pasting this:



    ssh user@host 'read foo; echo ">>$foo<<"'
    echo bar


    You will see >>echo bar<< as output from the echo on the server.



    This means that ssh will eat the pasted data on its standard input, as if you had done



    echo 'echo bar' | ssh user@host 'read foo; echo ">>$foo<<"'


    The solution to this, apart from never pasting shell commands into the terminal to run them, is to use ssh -n, which will redirect /dev/null into ssh:



    ssh -n user@host 'echo foo'
    echo bar



    Unfortunately I don't know the mechanics of pasting, so I can't say anything clever about why the pasted data ends up on the standard input stream of ssh, but I'm guessing it has to do with the stream being inherited from the interactive shell (which reads commands from standard input).




    Using ssh -n is also the solution (or at least a solution) to the issue of



    while read something; do
    ssh user@host 'somecommand'
    done <inputfile


    Here, the loop will only run once since ssh eats the data from inputfile.






    share|improve this answer



























      up vote
      1
      down vote



      accepted










      Try pasting this:



      ssh user@host 'read foo; echo ">>$foo<<"'
      echo bar


      You will see >>echo bar<< as output from the echo on the server.



      This means that ssh will eat the pasted data on its standard input, as if you had done



      echo 'echo bar' | ssh user@host 'read foo; echo ">>$foo<<"'


      The solution to this, apart from never pasting shell commands into the terminal to run them, is to use ssh -n, which will redirect /dev/null into ssh:



      ssh -n user@host 'echo foo'
      echo bar



      Unfortunately I don't know the mechanics of pasting, so I can't say anything clever about why the pasted data ends up on the standard input stream of ssh, but I'm guessing it has to do with the stream being inherited from the interactive shell (which reads commands from standard input).




      Using ssh -n is also the solution (or at least a solution) to the issue of



      while read something; do
      ssh user@host 'somecommand'
      done <inputfile


      Here, the loop will only run once since ssh eats the data from inputfile.






      share|improve this answer

























        up vote
        1
        down vote



        accepted







        up vote
        1
        down vote



        accepted






        Try pasting this:



        ssh user@host 'read foo; echo ">>$foo<<"'
        echo bar


        You will see >>echo bar<< as output from the echo on the server.



        This means that ssh will eat the pasted data on its standard input, as if you had done



        echo 'echo bar' | ssh user@host 'read foo; echo ">>$foo<<"'


        The solution to this, apart from never pasting shell commands into the terminal to run them, is to use ssh -n, which will redirect /dev/null into ssh:



        ssh -n user@host 'echo foo'
        echo bar



        Unfortunately I don't know the mechanics of pasting, so I can't say anything clever about why the pasted data ends up on the standard input stream of ssh, but I'm guessing it has to do with the stream being inherited from the interactive shell (which reads commands from standard input).




        Using ssh -n is also the solution (or at least a solution) to the issue of



        while read something; do
        ssh user@host 'somecommand'
        done <inputfile


        Here, the loop will only run once since ssh eats the data from inputfile.






        share|improve this answer















        Try pasting this:



        ssh user@host 'read foo; echo ">>$foo<<"'
        echo bar


        You will see >>echo bar<< as output from the echo on the server.



        This means that ssh will eat the pasted data on its standard input, as if you had done



        echo 'echo bar' | ssh user@host 'read foo; echo ">>$foo<<"'


        The solution to this, apart from never pasting shell commands into the terminal to run them, is to use ssh -n, which will redirect /dev/null into ssh:



        ssh -n user@host 'echo foo'
        echo bar



        Unfortunately I don't know the mechanics of pasting, so I can't say anything clever about why the pasted data ends up on the standard input stream of ssh, but I'm guessing it has to do with the stream being inherited from the interactive shell (which reads commands from standard input).




        Using ssh -n is also the solution (or at least a solution) to the issue of



        while read something; do
        ssh user@host 'somecommand'
        done <inputfile


        Here, the loop will only run once since ssh eats the data from inputfile.







        share|improve this answer















        share|improve this answer



        share|improve this answer








        edited Jun 25 at 22:06


























        answered Jun 25 at 19:24









        Kusalananda

        101k13199312




        101k13199312






















             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f451776%2fwhere-is-my-pasted-input-going%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?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay