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
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
New contributor
|
show 6 more comments
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
New contributor
1
Trying to understand... If thebuild-essential
were to fail, would you want to continue executing the other items?
– roaima
yesterday
Also, since you're (probably) running these commands viabash
, 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
doesapt install build-essential
prompt for input during the installation?
– Jeff Schaller♦
yesterday
|
show 6 more comments
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
New contributor
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
bash sudo clipboard
New contributor
New contributor
edited yesterday
0xSheepdog
1,6041924
1,6041924
New contributor
asked yesterday
MichaelMichael
83
83
New contributor
New contributor
1
Trying to understand... If thebuild-essential
were to fail, would you want to continue executing the other items?
– roaima
yesterday
Also, since you're (probably) running these commands viabash
, 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
doesapt install build-essential
prompt for input during the installation?
– Jeff Schaller♦
yesterday
|
show 6 more comments
1
Trying to understand... If thebuild-essential
were to fail, would you want to continue executing the other items?
– roaima
yesterday
Also, since you're (probably) running these commands viabash
, 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
doesapt 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
|
show 6 more comments
2 Answers
2
active
oldest
votes
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)
Awesome, that did it! So basicallysudo
andapt
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
add a comment |
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.
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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)
Awesome, that did it! So basicallysudo
andapt
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
add a comment |
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)
Awesome, that did it! So basicallysudo
andapt
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
add a comment |
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)
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)
edited yesterday
answered yesterday
LL3LL3
1565
1565
Awesome, that did it! So basicallysudo
andapt
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
add a comment |
Awesome, that did it! So basicallysudo
andapt
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
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered yesterday
0xSheepdog0xSheepdog
1,6041924
1,6041924
add a comment |
add a comment |
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.
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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