I paste a code in WSL but I get only part of it











up vote
1
down vote

favorite












I use Ubuntu 16.04 (xenial) via WSL.



I copy this code



#!/bin/bash
read -p "Have you created db credentials already?" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) exit;;
esac


When I paste it in Ubuntu I get only part of it:



read -p "Have you created db credentials already?" yn
Have you created db credentials already?


Why when it is pasted, it is pasted partially?



Update



I copy the code from GitHub, when the case conditions are indented with tabs and when the code is without a line break in the last line (no extra empty note after the last line).










share|improve this question
























  • Can't understand why this was down voted.
    – JohnDoea
    Nov 18 at 6:02










  • This usage is incorrect. Use shell script file instead of copying and pasting into terminal.
    – Alvin Liang
    Nov 18 at 19:28












  • @AlvinLiang I see no reason why it's necessarily incorrect, I have good experience with copy-pasting (when I find it elegant) or executing a script directly from GitHub without downloading it with git which is even more elegant: askubuntu.com/questions/992448/… but yes, indeed the usual way is to download a program with git and execute locally, it's just not something I want to do here.
    – JohnDoea
    Nov 18 at 22:41






  • 1




    It's incorrect because paste is an input behavior, and read -p expects user input. Even if it does not stop your paste the behavior will not be correct.
    – Alvin Liang
    2 days ago








  • 1




    @AlvinLiang seems what you write indicated it can only be run as part of a script and not as a command-set pasted in the terminal. This should be an answer IMO.
    – JohnDoea
    2 days ago















up vote
1
down vote

favorite












I use Ubuntu 16.04 (xenial) via WSL.



I copy this code



#!/bin/bash
read -p "Have you created db credentials already?" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) exit;;
esac


When I paste it in Ubuntu I get only part of it:



read -p "Have you created db credentials already?" yn
Have you created db credentials already?


Why when it is pasted, it is pasted partially?



Update



I copy the code from GitHub, when the case conditions are indented with tabs and when the code is without a line break in the last line (no extra empty note after the last line).










share|improve this question
























  • Can't understand why this was down voted.
    – JohnDoea
    Nov 18 at 6:02










  • This usage is incorrect. Use shell script file instead of copying and pasting into terminal.
    – Alvin Liang
    Nov 18 at 19:28












  • @AlvinLiang I see no reason why it's necessarily incorrect, I have good experience with copy-pasting (when I find it elegant) or executing a script directly from GitHub without downloading it with git which is even more elegant: askubuntu.com/questions/992448/… but yes, indeed the usual way is to download a program with git and execute locally, it's just not something I want to do here.
    – JohnDoea
    Nov 18 at 22:41






  • 1




    It's incorrect because paste is an input behavior, and read -p expects user input. Even if it does not stop your paste the behavior will not be correct.
    – Alvin Liang
    2 days ago








  • 1




    @AlvinLiang seems what you write indicated it can only be run as part of a script and not as a command-set pasted in the terminal. This should be an answer IMO.
    – JohnDoea
    2 days ago













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I use Ubuntu 16.04 (xenial) via WSL.



I copy this code



#!/bin/bash
read -p "Have you created db credentials already?" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) exit;;
esac


When I paste it in Ubuntu I get only part of it:



read -p "Have you created db credentials already?" yn
Have you created db credentials already?


Why when it is pasted, it is pasted partially?



Update



I copy the code from GitHub, when the case conditions are indented with tabs and when the code is without a line break in the last line (no extra empty note after the last line).










share|improve this question















I use Ubuntu 16.04 (xenial) via WSL.



I copy this code



#!/bin/bash
read -p "Have you created db credentials already?" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) exit;;
esac


When I paste it in Ubuntu I get only part of it:



read -p "Have you created db credentials already?" yn
Have you created db credentials already?


Why when it is pasted, it is pasted partially?



Update



I copy the code from GitHub, when the case conditions are indented with tabs and when the code is without a line break in the last line (no extra empty note after the last line).







16.04 command-line windows-subsystem-for-linux paste






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago

























asked Nov 17 at 9:23









JohnDoea

11592157




11592157












  • Can't understand why this was down voted.
    – JohnDoea
    Nov 18 at 6:02










  • This usage is incorrect. Use shell script file instead of copying and pasting into terminal.
    – Alvin Liang
    Nov 18 at 19:28












  • @AlvinLiang I see no reason why it's necessarily incorrect, I have good experience with copy-pasting (when I find it elegant) or executing a script directly from GitHub without downloading it with git which is even more elegant: askubuntu.com/questions/992448/… but yes, indeed the usual way is to download a program with git and execute locally, it's just not something I want to do here.
    – JohnDoea
    Nov 18 at 22:41






  • 1




    It's incorrect because paste is an input behavior, and read -p expects user input. Even if it does not stop your paste the behavior will not be correct.
    – Alvin Liang
    2 days ago








  • 1




    @AlvinLiang seems what you write indicated it can only be run as part of a script and not as a command-set pasted in the terminal. This should be an answer IMO.
    – JohnDoea
    2 days ago


















  • Can't understand why this was down voted.
    – JohnDoea
    Nov 18 at 6:02










  • This usage is incorrect. Use shell script file instead of copying and pasting into terminal.
    – Alvin Liang
    Nov 18 at 19:28












  • @AlvinLiang I see no reason why it's necessarily incorrect, I have good experience with copy-pasting (when I find it elegant) or executing a script directly from GitHub without downloading it with git which is even more elegant: askubuntu.com/questions/992448/… but yes, indeed the usual way is to download a program with git and execute locally, it's just not something I want to do here.
    – JohnDoea
    Nov 18 at 22:41






  • 1




    It's incorrect because paste is an input behavior, and read -p expects user input. Even if it does not stop your paste the behavior will not be correct.
    – Alvin Liang
    2 days ago








  • 1




    @AlvinLiang seems what you write indicated it can only be run as part of a script and not as a command-set pasted in the terminal. This should be an answer IMO.
    – JohnDoea
    2 days ago
















Can't understand why this was down voted.
– JohnDoea
Nov 18 at 6:02




Can't understand why this was down voted.
– JohnDoea
Nov 18 at 6:02












This usage is incorrect. Use shell script file instead of copying and pasting into terminal.
– Alvin Liang
Nov 18 at 19:28






This usage is incorrect. Use shell script file instead of copying and pasting into terminal.
– Alvin Liang
Nov 18 at 19:28














@AlvinLiang I see no reason why it's necessarily incorrect, I have good experience with copy-pasting (when I find it elegant) or executing a script directly from GitHub without downloading it with git which is even more elegant: askubuntu.com/questions/992448/… but yes, indeed the usual way is to download a program with git and execute locally, it's just not something I want to do here.
– JohnDoea
Nov 18 at 22:41




@AlvinLiang I see no reason why it's necessarily incorrect, I have good experience with copy-pasting (when I find it elegant) or executing a script directly from GitHub without downloading it with git which is even more elegant: askubuntu.com/questions/992448/… but yes, indeed the usual way is to download a program with git and execute locally, it's just not something I want to do here.
– JohnDoea
Nov 18 at 22:41




1




1




It's incorrect because paste is an input behavior, and read -p expects user input. Even if it does not stop your paste the behavior will not be correct.
– Alvin Liang
2 days ago






It's incorrect because paste is an input behavior, and read -p expects user input. Even if it does not stop your paste the behavior will not be correct.
– Alvin Liang
2 days ago






1




1




@AlvinLiang seems what you write indicated it can only be run as part of a script and not as a command-set pasted in the terminal. This should be an answer IMO.
– JohnDoea
2 days ago




@AlvinLiang seems what you write indicated it can only be run as part of a script and not as a command-set pasted in the terminal. This should be an answer IMO.
– JohnDoea
2 days ago










1 Answer
1






active

oldest

votes

















up vote
3
down vote



accepted










As soon as "read -p" line is invoked, terminal clears your original paste buffer because it's expecting meaningful user input, and you cannot just paste it into terminal like this.



If you don't feel like creating a script file, press ctrl-x and then ctrl-e in the terminal, it will bring up the default editor. Paste it into the editor, save and exit, dash will run you script correctly from a temp file.






share|improve this answer





















  • The correct default behavior: after press ctrl+x and then ctrl+e, the nano editor should be brought up. Paste you script in to the nano editor and save/exit, dash will run the script.
    – Alvin Liang
    2 days ago










  • nano does bring nano up. Anyway, I created x.sh with the code and executed the file. Hitting N executed break but hitting Y brought an error; x.sh: line 4: break: only meaningful in a for', while', or until' loop`. Do you have an idea why?
    – JohnDoea
    2 days ago








  • 1




    This is correct response, because your break command is meaningless here. You don't need to add break in every switch option like in C.
    – Alvin Liang
    2 days ago













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%2f1093677%2fi-paste-a-code-in-wsl-but-i-get-only-part-of-it%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
3
down vote



accepted










As soon as "read -p" line is invoked, terminal clears your original paste buffer because it's expecting meaningful user input, and you cannot just paste it into terminal like this.



If you don't feel like creating a script file, press ctrl-x and then ctrl-e in the terminal, it will bring up the default editor. Paste it into the editor, save and exit, dash will run you script correctly from a temp file.






share|improve this answer





















  • The correct default behavior: after press ctrl+x and then ctrl+e, the nano editor should be brought up. Paste you script in to the nano editor and save/exit, dash will run the script.
    – Alvin Liang
    2 days ago










  • nano does bring nano up. Anyway, I created x.sh with the code and executed the file. Hitting N executed break but hitting Y brought an error; x.sh: line 4: break: only meaningful in a for', while', or until' loop`. Do you have an idea why?
    – JohnDoea
    2 days ago








  • 1




    This is correct response, because your break command is meaningless here. You don't need to add break in every switch option like in C.
    – Alvin Liang
    2 days ago

















up vote
3
down vote



accepted










As soon as "read -p" line is invoked, terminal clears your original paste buffer because it's expecting meaningful user input, and you cannot just paste it into terminal like this.



If you don't feel like creating a script file, press ctrl-x and then ctrl-e in the terminal, it will bring up the default editor. Paste it into the editor, save and exit, dash will run you script correctly from a temp file.






share|improve this answer





















  • The correct default behavior: after press ctrl+x and then ctrl+e, the nano editor should be brought up. Paste you script in to the nano editor and save/exit, dash will run the script.
    – Alvin Liang
    2 days ago










  • nano does bring nano up. Anyway, I created x.sh with the code and executed the file. Hitting N executed break but hitting Y brought an error; x.sh: line 4: break: only meaningful in a for', while', or until' loop`. Do you have an idea why?
    – JohnDoea
    2 days ago








  • 1




    This is correct response, because your break command is meaningless here. You don't need to add break in every switch option like in C.
    – Alvin Liang
    2 days ago















up vote
3
down vote



accepted







up vote
3
down vote



accepted






As soon as "read -p" line is invoked, terminal clears your original paste buffer because it's expecting meaningful user input, and you cannot just paste it into terminal like this.



If you don't feel like creating a script file, press ctrl-x and then ctrl-e in the terminal, it will bring up the default editor. Paste it into the editor, save and exit, dash will run you script correctly from a temp file.






share|improve this answer












As soon as "read -p" line is invoked, terminal clears your original paste buffer because it's expecting meaningful user input, and you cannot just paste it into terminal like this.



If you don't feel like creating a script file, press ctrl-x and then ctrl-e in the terminal, it will bring up the default editor. Paste it into the editor, save and exit, dash will run you script correctly from a temp file.







share|improve this answer












share|improve this answer



share|improve this answer










answered 2 days ago









Alvin Liang

3216




3216












  • The correct default behavior: after press ctrl+x and then ctrl+e, the nano editor should be brought up. Paste you script in to the nano editor and save/exit, dash will run the script.
    – Alvin Liang
    2 days ago










  • nano does bring nano up. Anyway, I created x.sh with the code and executed the file. Hitting N executed break but hitting Y brought an error; x.sh: line 4: break: only meaningful in a for', while', or until' loop`. Do you have an idea why?
    – JohnDoea
    2 days ago








  • 1




    This is correct response, because your break command is meaningless here. You don't need to add break in every switch option like in C.
    – Alvin Liang
    2 days ago




















  • The correct default behavior: after press ctrl+x and then ctrl+e, the nano editor should be brought up. Paste you script in to the nano editor and save/exit, dash will run the script.
    – Alvin Liang
    2 days ago










  • nano does bring nano up. Anyway, I created x.sh with the code and executed the file. Hitting N executed break but hitting Y brought an error; x.sh: line 4: break: only meaningful in a for', while', or until' loop`. Do you have an idea why?
    – JohnDoea
    2 days ago








  • 1




    This is correct response, because your break command is meaningless here. You don't need to add break in every switch option like in C.
    – Alvin Liang
    2 days ago


















The correct default behavior: after press ctrl+x and then ctrl+e, the nano editor should be brought up. Paste you script in to the nano editor and save/exit, dash will run the script.
– Alvin Liang
2 days ago




The correct default behavior: after press ctrl+x and then ctrl+e, the nano editor should be brought up. Paste you script in to the nano editor and save/exit, dash will run the script.
– Alvin Liang
2 days ago












nano does bring nano up. Anyway, I created x.sh with the code and executed the file. Hitting N executed break but hitting Y brought an error; x.sh: line 4: break: only meaningful in a for', while', or until' loop`. Do you have an idea why?
– JohnDoea
2 days ago






nano does bring nano up. Anyway, I created x.sh with the code and executed the file. Hitting N executed break but hitting Y brought an error; x.sh: line 4: break: only meaningful in a for', while', or until' loop`. Do you have an idea why?
– JohnDoea
2 days ago






1




1




This is correct response, because your break command is meaningless here. You don't need to add break in every switch option like in C.
– Alvin Liang
2 days ago






This is correct response, because your break command is meaningless here. You don't need to add break in every switch option like in C.
– Alvin Liang
2 days ago




















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1093677%2fi-paste-a-code-in-wsl-but-i-get-only-part-of-it%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

Quarter-circle Tiles

build a pushdown automaton that recognizes the reverse language of a given pushdown automaton?

Mont Emei