How to avoid paste of multiline text on ubuntu command line?











up vote
3
down vote

favorite
1












This question may sound weird. But here is what happened and I'd like to find out the ways to avoid this happening again.



I accidentally pasted contents of a text file into SSH CLI on Ubuntu 16.04. The machine was used for my production setup. I actually copied contents of a log file and intended to paste it in a nano editor opened in some other SSH window, but mistakenly pasted it on command line interface. The shell attempted to process every line as a command and created some junk files in local directory.



This fortunately didn't cause much damage however I want to know is there any way to avoid the accidental paste on ubuntu command line? Or can I disable the command line for multiline inputs?



I use PAC ssh client to connect to my remote systems.










share|improve this question


















  • 2




    I'm not familiar with PAC, however maybe you can implement something equivalent to this? Prevent accidental execution of commands in Linux if pasting text containing one or more return characters
    – steeldriver
    Jul 20 at 11:41






  • 1




    That's precisely what I am looking for. Will check if something like that possible for PAC or any other SSH clients on Ubuntu.
    – Pawan
    Jul 20 at 15:45






  • 2




    You might want to google "bracketed paste" as well - see for example prevent multi-line paste in bash
    – steeldriver
    Jul 20 at 15:49

















up vote
3
down vote

favorite
1












This question may sound weird. But here is what happened and I'd like to find out the ways to avoid this happening again.



I accidentally pasted contents of a text file into SSH CLI on Ubuntu 16.04. The machine was used for my production setup. I actually copied contents of a log file and intended to paste it in a nano editor opened in some other SSH window, but mistakenly pasted it on command line interface. The shell attempted to process every line as a command and created some junk files in local directory.



This fortunately didn't cause much damage however I want to know is there any way to avoid the accidental paste on ubuntu command line? Or can I disable the command line for multiline inputs?



I use PAC ssh client to connect to my remote systems.










share|improve this question


















  • 2




    I'm not familiar with PAC, however maybe you can implement something equivalent to this? Prevent accidental execution of commands in Linux if pasting text containing one or more return characters
    – steeldriver
    Jul 20 at 11:41






  • 1




    That's precisely what I am looking for. Will check if something like that possible for PAC or any other SSH clients on Ubuntu.
    – Pawan
    Jul 20 at 15:45






  • 2




    You might want to google "bracketed paste" as well - see for example prevent multi-line paste in bash
    – steeldriver
    Jul 20 at 15:49















up vote
3
down vote

favorite
1









up vote
3
down vote

favorite
1






1





This question may sound weird. But here is what happened and I'd like to find out the ways to avoid this happening again.



I accidentally pasted contents of a text file into SSH CLI on Ubuntu 16.04. The machine was used for my production setup. I actually copied contents of a log file and intended to paste it in a nano editor opened in some other SSH window, but mistakenly pasted it on command line interface. The shell attempted to process every line as a command and created some junk files in local directory.



This fortunately didn't cause much damage however I want to know is there any way to avoid the accidental paste on ubuntu command line? Or can I disable the command line for multiline inputs?



I use PAC ssh client to connect to my remote systems.










share|improve this question













This question may sound weird. But here is what happened and I'd like to find out the ways to avoid this happening again.



I accidentally pasted contents of a text file into SSH CLI on Ubuntu 16.04. The machine was used for my production setup. I actually copied contents of a log file and intended to paste it in a nano editor opened in some other SSH window, but mistakenly pasted it on command line interface. The shell attempted to process every line as a command and created some junk files in local directory.



This fortunately didn't cause much damage however I want to know is there any way to avoid the accidental paste on ubuntu command line? Or can I disable the command line for multiline inputs?



I use PAC ssh client to connect to my remote systems.







16.04 command-line






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jul 20 at 11:13









Pawan

15116




15116








  • 2




    I'm not familiar with PAC, however maybe you can implement something equivalent to this? Prevent accidental execution of commands in Linux if pasting text containing one or more return characters
    – steeldriver
    Jul 20 at 11:41






  • 1




    That's precisely what I am looking for. Will check if something like that possible for PAC or any other SSH clients on Ubuntu.
    – Pawan
    Jul 20 at 15:45






  • 2




    You might want to google "bracketed paste" as well - see for example prevent multi-line paste in bash
    – steeldriver
    Jul 20 at 15:49
















  • 2




    I'm not familiar with PAC, however maybe you can implement something equivalent to this? Prevent accidental execution of commands in Linux if pasting text containing one or more return characters
    – steeldriver
    Jul 20 at 11:41






  • 1




    That's precisely what I am looking for. Will check if something like that possible for PAC or any other SSH clients on Ubuntu.
    – Pawan
    Jul 20 at 15:45






  • 2




    You might want to google "bracketed paste" as well - see for example prevent multi-line paste in bash
    – steeldriver
    Jul 20 at 15:49










2




2




I'm not familiar with PAC, however maybe you can implement something equivalent to this? Prevent accidental execution of commands in Linux if pasting text containing one or more return characters
– steeldriver
Jul 20 at 11:41




I'm not familiar with PAC, however maybe you can implement something equivalent to this? Prevent accidental execution of commands in Linux if pasting text containing one or more return characters
– steeldriver
Jul 20 at 11:41




1




1




That's precisely what I am looking for. Will check if something like that possible for PAC or any other SSH clients on Ubuntu.
– Pawan
Jul 20 at 15:45




That's precisely what I am looking for. Will check if something like that possible for PAC or any other SSH clients on Ubuntu.
– Pawan
Jul 20 at 15:45




2




2




You might want to google "bracketed paste" as well - see for example prevent multi-line paste in bash
– steeldriver
Jul 20 at 15:49






You might want to google "bracketed paste" as well - see for example prevent multi-line paste in bash
– steeldriver
Jul 20 at 15:49












1 Answer
1






active

oldest

votes

















up vote
1
down vote













Bracketed paste may be what you need. Assuming you are running a terminal that supports it (e.g., xterm, putty, gnome-terminal), and assuming you are running the bash shell, all you have to do is execute this command in each terminal:



set enable-bracketed-paste


You can even put this command at the end of your .bashrc. From that moment on, any stuff you paste into the shell will not be immediately executed, even if it contains newlines. However, if you paste one or more lines and then hit 'enter' manually, all of the lines will be executed - so if you pasted something by mistake and don't want it executed, you must hit 'Ctrl-C' instead of 'enter'.



Caveat 1: bracketed paste will also be enabled for any programs you run in the shell. Many programs don't understand it. So if you run cat and then paste the word hello, you will see ^[[200~hello^[[201~ instead. This may not be what you want.



Caveat 2: some programs, such as vi or emacs -nw, will disable bracketed paste after they finish running, even if it was turned on before they ran. You could work around this by enabling bracketed-paste with every prompt. One way to do this would be to redefine $PS1 to include the escape sequence $'e[?2004h'. This may be a bit esoteric.






share|improve this answer





















    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "89"
    };
    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: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    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%2faskubuntu.com%2fquestions%2f1057855%2fhow-to-avoid-paste-of-multiline-text-on-ubuntu-command-line%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








    up vote
    1
    down vote













    Bracketed paste may be what you need. Assuming you are running a terminal that supports it (e.g., xterm, putty, gnome-terminal), and assuming you are running the bash shell, all you have to do is execute this command in each terminal:



    set enable-bracketed-paste


    You can even put this command at the end of your .bashrc. From that moment on, any stuff you paste into the shell will not be immediately executed, even if it contains newlines. However, if you paste one or more lines and then hit 'enter' manually, all of the lines will be executed - so if you pasted something by mistake and don't want it executed, you must hit 'Ctrl-C' instead of 'enter'.



    Caveat 1: bracketed paste will also be enabled for any programs you run in the shell. Many programs don't understand it. So if you run cat and then paste the word hello, you will see ^[[200~hello^[[201~ instead. This may not be what you want.



    Caveat 2: some programs, such as vi or emacs -nw, will disable bracketed paste after they finish running, even if it was turned on before they ran. You could work around this by enabling bracketed-paste with every prompt. One way to do this would be to redefine $PS1 to include the escape sequence $'e[?2004h'. This may be a bit esoteric.






    share|improve this answer

























      up vote
      1
      down vote













      Bracketed paste may be what you need. Assuming you are running a terminal that supports it (e.g., xterm, putty, gnome-terminal), and assuming you are running the bash shell, all you have to do is execute this command in each terminal:



      set enable-bracketed-paste


      You can even put this command at the end of your .bashrc. From that moment on, any stuff you paste into the shell will not be immediately executed, even if it contains newlines. However, if you paste one or more lines and then hit 'enter' manually, all of the lines will be executed - so if you pasted something by mistake and don't want it executed, you must hit 'Ctrl-C' instead of 'enter'.



      Caveat 1: bracketed paste will also be enabled for any programs you run in the shell. Many programs don't understand it. So if you run cat and then paste the word hello, you will see ^[[200~hello^[[201~ instead. This may not be what you want.



      Caveat 2: some programs, such as vi or emacs -nw, will disable bracketed paste after they finish running, even if it was turned on before they ran. You could work around this by enabling bracketed-paste with every prompt. One way to do this would be to redefine $PS1 to include the escape sequence $'e[?2004h'. This may be a bit esoteric.






      share|improve this answer























        up vote
        1
        down vote










        up vote
        1
        down vote









        Bracketed paste may be what you need. Assuming you are running a terminal that supports it (e.g., xterm, putty, gnome-terminal), and assuming you are running the bash shell, all you have to do is execute this command in each terminal:



        set enable-bracketed-paste


        You can even put this command at the end of your .bashrc. From that moment on, any stuff you paste into the shell will not be immediately executed, even if it contains newlines. However, if you paste one or more lines and then hit 'enter' manually, all of the lines will be executed - so if you pasted something by mistake and don't want it executed, you must hit 'Ctrl-C' instead of 'enter'.



        Caveat 1: bracketed paste will also be enabled for any programs you run in the shell. Many programs don't understand it. So if you run cat and then paste the word hello, you will see ^[[200~hello^[[201~ instead. This may not be what you want.



        Caveat 2: some programs, such as vi or emacs -nw, will disable bracketed paste after they finish running, even if it was turned on before they ran. You could work around this by enabling bracketed-paste with every prompt. One way to do this would be to redefine $PS1 to include the escape sequence $'e[?2004h'. This may be a bit esoteric.






        share|improve this answer












        Bracketed paste may be what you need. Assuming you are running a terminal that supports it (e.g., xterm, putty, gnome-terminal), and assuming you are running the bash shell, all you have to do is execute this command in each terminal:



        set enable-bracketed-paste


        You can even put this command at the end of your .bashrc. From that moment on, any stuff you paste into the shell will not be immediately executed, even if it contains newlines. However, if you paste one or more lines and then hit 'enter' manually, all of the lines will be executed - so if you pasted something by mistake and don't want it executed, you must hit 'Ctrl-C' instead of 'enter'.



        Caveat 1: bracketed paste will also be enabled for any programs you run in the shell. Many programs don't understand it. So if you run cat and then paste the word hello, you will see ^[[200~hello^[[201~ instead. This may not be what you want.



        Caveat 2: some programs, such as vi or emacs -nw, will disable bracketed paste after they finish running, even if it was turned on before they ran. You could work around this by enabling bracketed-paste with every prompt. One way to do this would be to redefine $PS1 to include the escape sequence $'e[?2004h'. This may be a bit esoteric.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 22 at 18:49









        Peter Selinger

        262




        262






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Ask Ubuntu!


            • 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%2faskubuntu.com%2fquestions%2f1057855%2fhow-to-avoid-paste-of-multiline-text-on-ubuntu-command-line%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 change which sound is reproduced for terminal bell?

            Can I use Tabulator js library in my java Spring + Thymeleaf project?

            Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents