How to execute several commands after each other with one request to the terminal (without using a file)?Run .sh file in one line commandWhich one is better: using ; or && to execute multiple commands in one line?Why combine commands on a single line in a Bash script?Using the SHIFT key in Terminalbash terminal/console strange overlapping behaviorEnable global terminal movement keysUnity Launcher missing and Terminal shortcut stopped workingFunction to change title doesn't work when run in scriptKeyboard lockup when typing <ctrl><shift> and random charactersclear meaning of .* in regexTerminal stops working after I run a command

How to join many tables side by side?

I am ask to complete my withdrawal transaction with COT fee of 1200 dollars

Why is 1>a.txt 2>&1 different from 1>a.txt 2>a.txt ? (Example shown)

Sorting marbles based on weightings

Do the Jovians in "Victory Unintentional" exist in Isaac Asimov's Foundation series?

Would a uranium 235 fuel pellet the size of Earth explode?

Why is Trump not being impeached for bribery?

Is it safe to wear earplugs in flight?

Is paying for portrait photos good for the people in the community you're photographing?

Why is wired Ethernet losing its speed advantage over wireless?

What was the first "Opening Repertoire" book?

I've never seen this before. Is this primarily a "rote computational trick" for multiplication by 9 ...?

What is the narrative difference between a Charisma and Wisdom saving throw?

Finding the right insults

Is Kirk’s comment about “LDS” intended to be a religious joke?

Is a datagram from an upper network layer converted 1:1 to one of the lower layer?

Avoid long walking when changing between Tokyo subway lines

Is the net charge on a capacitor zero? If yes, then why?

Why don't the absolute value functions in C accept const inputs?

Does 'hacer alguien matar' mean to make somebody kill or to get sb killed?

Shp is not valid or recognized data source using QGIS

Have spacecraft photographed each other beyond Earth orbit?

Is the weight of the aircraft flying in the sky transferred to the ground?

Short story: Man gains X-ray vision, cheats at cards, sees a clot in his blood



How to execute several commands after each other with one request to the terminal (without using a file)?


Run .sh file in one line commandWhich one is better: using ; or && to execute multiple commands in one line?Why combine commands on a single line in a Bash script?Using the SHIFT key in Terminalbash terminal/console strange overlapping behaviorEnable global terminal movement keysUnity Launcher missing and Terminal shortcut stopped workingFunction to change title doesn't work when run in scriptKeyboard lockup when typing <ctrl><shift> and random charactersclear meaning of .* in regexTerminal stops working after I run a command






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;









22


















I could (1) prepare a file with typed commands separated by end-line, (2) make it executable, (3) run it from a file-system manager or the terminal.



But this is ridiculous for not repeatable and every-time-other sets of commands.



Can I type those commands to the terminal in one request instead?



I don't know end-line character for the terminal - Ctrl, Shift or Alt with Enter doesn't work.  










share|improve this question






















  • 1





    On a command line, commands can be separated with a semicolon.

    – John1024
    Feb 1 '14 at 2:55

















22


















I could (1) prepare a file with typed commands separated by end-line, (2) make it executable, (3) run it from a file-system manager or the terminal.



But this is ridiculous for not repeatable and every-time-other sets of commands.



Can I type those commands to the terminal in one request instead?



I don't know end-line character for the terminal - Ctrl, Shift or Alt with Enter doesn't work.  










share|improve this question






















  • 1





    On a command line, commands can be separated with a semicolon.

    – John1024
    Feb 1 '14 at 2:55













22













22









22


9






I could (1) prepare a file with typed commands separated by end-line, (2) make it executable, (3) run it from a file-system manager or the terminal.



But this is ridiculous for not repeatable and every-time-other sets of commands.



Can I type those commands to the terminal in one request instead?



I don't know end-line character for the terminal - Ctrl, Shift or Alt with Enter doesn't work.  










share|improve this question
















I could (1) prepare a file with typed commands separated by end-line, (2) make it executable, (3) run it from a file-system manager or the terminal.



But this is ridiculous for not repeatable and every-time-other sets of commands.



Can I type those commands to the terminal in one request instead?



I don't know end-line character for the terminal - Ctrl, Shift or Alt with Enter doesn't work.  







gnome-terminal command-line






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Oct 1 at 9:21









Asaf M

2991 silver badge4 bronze badges




2991 silver badge4 bronze badges










asked Feb 1 '14 at 2:49









EsamoEsamo

1,3622 gold badges11 silver badges25 bronze badges




1,3622 gold badges11 silver badges25 bronze badges










  • 1





    On a command line, commands can be separated with a semicolon.

    – John1024
    Feb 1 '14 at 2:55












  • 1





    On a command line, commands can be separated with a semicolon.

    – John1024
    Feb 1 '14 at 2:55







1




1





On a command line, commands can be separated with a semicolon.

– John1024
Feb 1 '14 at 2:55





On a command line, commands can be separated with a semicolon.

– John1024
Feb 1 '14 at 2:55










3 Answers
3






active

oldest

votes


















27



















You can separate commands with && or ;.




  • && only runs the next command if the previous one exited with status 0 (was successful) :



    command1 && command2 && command3



  • ; runs every commands, even if the previous one exits with a non zero status :



    command1; command2; command3


You can combine these separators as you wish.






share|improve this answer






















  • 6





    for command1 && command2 command2 will only be executed if command1 is successful.

    – souravc
    Feb 1 '14 at 3:18











  • Nice discussions, relevant/similar posts: askubuntu.com/questions/334994/… stackoverflow.com/questions/13077241/…

    – gevang
    Feb 1 '14 at 4:04











  • @souravc : I made an edit, thanks, I learned something.

    – MrVaykadji
    Feb 1 '14 at 10:27











  • if combining sudo apt upgrade and sudo systemctl reboot, would you need to add 'sudo' twice, or will it 'remember' sudo for the second command?

    – Koen
    Jan 6 at 21:09


















9



















If you are interested to type each command on its own line in one single request you can use the following method:



  • Start your request (first line) with if :; then (this mean: if true, then do) and press Enter; your prompt will change now in > and nothing will be executed.


  • Type your commands, each one followed by Enter


  • Finish your request with with fi (end of the above if condition) and press Enter. Now all your commands will be executed in the given order.


Example:



radu@Radu: ~ $ if :; then
> echo 'something'
> echo 'something else'
> echo 'List current directory contents:'
> ls
> echo 'Change current directory with root directory:'
> cd
> #finish
> fi
something
something else
List current directory contents:
Backups Desktop forma3d Public Untitled txt.txt~
bin Documente Music Templates Videos
configuration.php examples.desktop passwd~ tmp~
Downloads file~ Poze Ubuntu One
Change current directory with root directory:
radu@Radu: / $





share|improve this answer

























  • if true; then may be clearer to read if so desired. : may be confused with the ; at first glance.

    – kiri
    Feb 1 '14 at 10:45



















4



















First, put a on its own line.

Then, insert your commands.

Then, put a on a new line and press Enter. Your commands will be executed.



Example:




echo list
echo of
echo commands
echo to run at once



which will print (all at once, with no prompt in between):



list
of
commands
to run at once


As a side note, .. is the Bash command grouping syntax. It's often useful in conjunction with && or || ('and', and 'or' respectively)






share|improve this answer



























  • Is that the same that if :; then already mentionned ? Or is it slightly different ?

    – MrVaykadji
    Feb 1 '14 at 10:38






  • 1





    @MrVaykadji It's the same outcome, but a different method. if : runs a test on the null command, which will always return true. .. just groups the commands together. I personally find .. easier to remember.

    – kiri
    Feb 1 '14 at 10:39













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',
autoActivateHeartbeat: false,
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/4.0/"u003ecc by-sa 4.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%2f413866%2fhow-to-execute-several-commands-after-each-other-with-one-request-to-the-termina%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown


























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes









27



















You can separate commands with && or ;.




  • && only runs the next command if the previous one exited with status 0 (was successful) :



    command1 && command2 && command3



  • ; runs every commands, even if the previous one exits with a non zero status :



    command1; command2; command3


You can combine these separators as you wish.






share|improve this answer






















  • 6





    for command1 && command2 command2 will only be executed if command1 is successful.

    – souravc
    Feb 1 '14 at 3:18











  • Nice discussions, relevant/similar posts: askubuntu.com/questions/334994/… stackoverflow.com/questions/13077241/…

    – gevang
    Feb 1 '14 at 4:04











  • @souravc : I made an edit, thanks, I learned something.

    – MrVaykadji
    Feb 1 '14 at 10:27











  • if combining sudo apt upgrade and sudo systemctl reboot, would you need to add 'sudo' twice, or will it 'remember' sudo for the second command?

    – Koen
    Jan 6 at 21:09















27



















You can separate commands with && or ;.




  • && only runs the next command if the previous one exited with status 0 (was successful) :



    command1 && command2 && command3



  • ; runs every commands, even if the previous one exits with a non zero status :



    command1; command2; command3


You can combine these separators as you wish.






share|improve this answer






















  • 6





    for command1 && command2 command2 will only be executed if command1 is successful.

    – souravc
    Feb 1 '14 at 3:18











  • Nice discussions, relevant/similar posts: askubuntu.com/questions/334994/… stackoverflow.com/questions/13077241/…

    – gevang
    Feb 1 '14 at 4:04











  • @souravc : I made an edit, thanks, I learned something.

    – MrVaykadji
    Feb 1 '14 at 10:27











  • if combining sudo apt upgrade and sudo systemctl reboot, would you need to add 'sudo' twice, or will it 'remember' sudo for the second command?

    – Koen
    Jan 6 at 21:09













27















27











27









You can separate commands with && or ;.




  • && only runs the next command if the previous one exited with status 0 (was successful) :



    command1 && command2 && command3



  • ; runs every commands, even if the previous one exits with a non zero status :



    command1; command2; command3


You can combine these separators as you wish.






share|improve this answer
















You can separate commands with && or ;.




  • && only runs the next command if the previous one exited with status 0 (was successful) :



    command1 && command2 && command3



  • ; runs every commands, even if the previous one exits with a non zero status :



    command1; command2; command3


You can combine these separators as you wish.







share|improve this answer















share|improve this answer




share|improve this answer








edited Feb 1 '14 at 10:25

























answered Feb 1 '14 at 2:55









MrVaykadjiMrVaykadji

4,6622 gold badges24 silver badges52 bronze badges




4,6622 gold badges24 silver badges52 bronze badges










  • 6





    for command1 && command2 command2 will only be executed if command1 is successful.

    – souravc
    Feb 1 '14 at 3:18











  • Nice discussions, relevant/similar posts: askubuntu.com/questions/334994/… stackoverflow.com/questions/13077241/…

    – gevang
    Feb 1 '14 at 4:04











  • @souravc : I made an edit, thanks, I learned something.

    – MrVaykadji
    Feb 1 '14 at 10:27











  • if combining sudo apt upgrade and sudo systemctl reboot, would you need to add 'sudo' twice, or will it 'remember' sudo for the second command?

    – Koen
    Jan 6 at 21:09












  • 6





    for command1 && command2 command2 will only be executed if command1 is successful.

    – souravc
    Feb 1 '14 at 3:18











  • Nice discussions, relevant/similar posts: askubuntu.com/questions/334994/… stackoverflow.com/questions/13077241/…

    – gevang
    Feb 1 '14 at 4:04











  • @souravc : I made an edit, thanks, I learned something.

    – MrVaykadji
    Feb 1 '14 at 10:27











  • if combining sudo apt upgrade and sudo systemctl reboot, would you need to add 'sudo' twice, or will it 'remember' sudo for the second command?

    – Koen
    Jan 6 at 21:09







6




6





for command1 && command2 command2 will only be executed if command1 is successful.

– souravc
Feb 1 '14 at 3:18





for command1 && command2 command2 will only be executed if command1 is successful.

– souravc
Feb 1 '14 at 3:18













Nice discussions, relevant/similar posts: askubuntu.com/questions/334994/… stackoverflow.com/questions/13077241/…

– gevang
Feb 1 '14 at 4:04





Nice discussions, relevant/similar posts: askubuntu.com/questions/334994/… stackoverflow.com/questions/13077241/…

– gevang
Feb 1 '14 at 4:04













@souravc : I made an edit, thanks, I learned something.

– MrVaykadji
Feb 1 '14 at 10:27





@souravc : I made an edit, thanks, I learned something.

– MrVaykadji
Feb 1 '14 at 10:27













if combining sudo apt upgrade and sudo systemctl reboot, would you need to add 'sudo' twice, or will it 'remember' sudo for the second command?

– Koen
Jan 6 at 21:09





if combining sudo apt upgrade and sudo systemctl reboot, would you need to add 'sudo' twice, or will it 'remember' sudo for the second command?

– Koen
Jan 6 at 21:09













9



















If you are interested to type each command on its own line in one single request you can use the following method:



  • Start your request (first line) with if :; then (this mean: if true, then do) and press Enter; your prompt will change now in > and nothing will be executed.


  • Type your commands, each one followed by Enter


  • Finish your request with with fi (end of the above if condition) and press Enter. Now all your commands will be executed in the given order.


Example:



radu@Radu: ~ $ if :; then
> echo 'something'
> echo 'something else'
> echo 'List current directory contents:'
> ls
> echo 'Change current directory with root directory:'
> cd
> #finish
> fi
something
something else
List current directory contents:
Backups Desktop forma3d Public Untitled txt.txt~
bin Documente Music Templates Videos
configuration.php examples.desktop passwd~ tmp~
Downloads file~ Poze Ubuntu One
Change current directory with root directory:
radu@Radu: / $





share|improve this answer

























  • if true; then may be clearer to read if so desired. : may be confused with the ; at first glance.

    – kiri
    Feb 1 '14 at 10:45
















9



















If you are interested to type each command on its own line in one single request you can use the following method:



  • Start your request (first line) with if :; then (this mean: if true, then do) and press Enter; your prompt will change now in > and nothing will be executed.


  • Type your commands, each one followed by Enter


  • Finish your request with with fi (end of the above if condition) and press Enter. Now all your commands will be executed in the given order.


Example:



radu@Radu: ~ $ if :; then
> echo 'something'
> echo 'something else'
> echo 'List current directory contents:'
> ls
> echo 'Change current directory with root directory:'
> cd
> #finish
> fi
something
something else
List current directory contents:
Backups Desktop forma3d Public Untitled txt.txt~
bin Documente Music Templates Videos
configuration.php examples.desktop passwd~ tmp~
Downloads file~ Poze Ubuntu One
Change current directory with root directory:
radu@Radu: / $





share|improve this answer

























  • if true; then may be clearer to read if so desired. : may be confused with the ; at first glance.

    – kiri
    Feb 1 '14 at 10:45














9















9











9









If you are interested to type each command on its own line in one single request you can use the following method:



  • Start your request (first line) with if :; then (this mean: if true, then do) and press Enter; your prompt will change now in > and nothing will be executed.


  • Type your commands, each one followed by Enter


  • Finish your request with with fi (end of the above if condition) and press Enter. Now all your commands will be executed in the given order.


Example:



radu@Radu: ~ $ if :; then
> echo 'something'
> echo 'something else'
> echo 'List current directory contents:'
> ls
> echo 'Change current directory with root directory:'
> cd
> #finish
> fi
something
something else
List current directory contents:
Backups Desktop forma3d Public Untitled txt.txt~
bin Documente Music Templates Videos
configuration.php examples.desktop passwd~ tmp~
Downloads file~ Poze Ubuntu One
Change current directory with root directory:
radu@Radu: / $





share|improve this answer














If you are interested to type each command on its own line in one single request you can use the following method:



  • Start your request (first line) with if :; then (this mean: if true, then do) and press Enter; your prompt will change now in > and nothing will be executed.


  • Type your commands, each one followed by Enter


  • Finish your request with with fi (end of the above if condition) and press Enter. Now all your commands will be executed in the given order.


Example:



radu@Radu: ~ $ if :; then
> echo 'something'
> echo 'something else'
> echo 'List current directory contents:'
> ls
> echo 'Change current directory with root directory:'
> cd
> #finish
> fi
something
something else
List current directory contents:
Backups Desktop forma3d Public Untitled txt.txt~
bin Documente Music Templates Videos
configuration.php examples.desktop passwd~ tmp~
Downloads file~ Poze Ubuntu One
Change current directory with root directory:
radu@Radu: / $






share|improve this answer













share|improve this answer




share|improve this answer










answered Feb 1 '14 at 7:11









Radu RădeanuRadu Rădeanu

132k38 gold badges276 silver badges343 bronze badges




132k38 gold badges276 silver badges343 bronze badges















  • if true; then may be clearer to read if so desired. : may be confused with the ; at first glance.

    – kiri
    Feb 1 '14 at 10:45


















  • if true; then may be clearer to read if so desired. : may be confused with the ; at first glance.

    – kiri
    Feb 1 '14 at 10:45

















if true; then may be clearer to read if so desired. : may be confused with the ; at first glance.

– kiri
Feb 1 '14 at 10:45






if true; then may be clearer to read if so desired. : may be confused with the ; at first glance.

– kiri
Feb 1 '14 at 10:45












4



















First, put a on its own line.

Then, insert your commands.

Then, put a on a new line and press Enter. Your commands will be executed.



Example:




echo list
echo of
echo commands
echo to run at once



which will print (all at once, with no prompt in between):



list
of
commands
to run at once


As a side note, .. is the Bash command grouping syntax. It's often useful in conjunction with && or || ('and', and 'or' respectively)






share|improve this answer



























  • Is that the same that if :; then already mentionned ? Or is it slightly different ?

    – MrVaykadji
    Feb 1 '14 at 10:38






  • 1





    @MrVaykadji It's the same outcome, but a different method. if : runs a test on the null command, which will always return true. .. just groups the commands together. I personally find .. easier to remember.

    – kiri
    Feb 1 '14 at 10:39
















4



















First, put a on its own line.

Then, insert your commands.

Then, put a on a new line and press Enter. Your commands will be executed.



Example:




echo list
echo of
echo commands
echo to run at once



which will print (all at once, with no prompt in between):



list
of
commands
to run at once


As a side note, .. is the Bash command grouping syntax. It's often useful in conjunction with && or || ('and', and 'or' respectively)






share|improve this answer



























  • Is that the same that if :; then already mentionned ? Or is it slightly different ?

    – MrVaykadji
    Feb 1 '14 at 10:38






  • 1





    @MrVaykadji It's the same outcome, but a different method. if : runs a test on the null command, which will always return true. .. just groups the commands together. I personally find .. easier to remember.

    – kiri
    Feb 1 '14 at 10:39














4















4











4









First, put a on its own line.

Then, insert your commands.

Then, put a on a new line and press Enter. Your commands will be executed.



Example:




echo list
echo of
echo commands
echo to run at once



which will print (all at once, with no prompt in between):



list
of
commands
to run at once


As a side note, .. is the Bash command grouping syntax. It's often useful in conjunction with && or || ('and', and 'or' respectively)






share|improve this answer
















First, put a on its own line.

Then, insert your commands.

Then, put a on a new line and press Enter. Your commands will be executed.



Example:




echo list
echo of
echo commands
echo to run at once



which will print (all at once, with no prompt in between):



list
of
commands
to run at once


As a side note, .. is the Bash command grouping syntax. It's often useful in conjunction with && or || ('and', and 'or' respectively)







share|improve this answer















share|improve this answer




share|improve this answer








edited Feb 1 '14 at 10:41

























answered Feb 1 '14 at 10:34









kirikiri

22.4k15 gold badges63 silver badges107 bronze badges




22.4k15 gold badges63 silver badges107 bronze badges















  • Is that the same that if :; then already mentionned ? Or is it slightly different ?

    – MrVaykadji
    Feb 1 '14 at 10:38






  • 1





    @MrVaykadji It's the same outcome, but a different method. if : runs a test on the null command, which will always return true. .. just groups the commands together. I personally find .. easier to remember.

    – kiri
    Feb 1 '14 at 10:39


















  • Is that the same that if :; then already mentionned ? Or is it slightly different ?

    – MrVaykadji
    Feb 1 '14 at 10:38






  • 1





    @MrVaykadji It's the same outcome, but a different method. if : runs a test on the null command, which will always return true. .. just groups the commands together. I personally find .. easier to remember.

    – kiri
    Feb 1 '14 at 10:39

















Is that the same that if :; then already mentionned ? Or is it slightly different ?

– MrVaykadji
Feb 1 '14 at 10:38





Is that the same that if :; then already mentionned ? Or is it slightly different ?

– MrVaykadji
Feb 1 '14 at 10:38




1




1





@MrVaykadji It's the same outcome, but a different method. if : runs a test on the null command, which will always return true. .. just groups the commands together. I personally find .. easier to remember.

– kiri
Feb 1 '14 at 10:39






@MrVaykadji It's the same outcome, but a different method. if : runs a test on the null command, which will always return true. .. just groups the commands together. I personally find .. easier to remember.

– kiri
Feb 1 '14 at 10:39



















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.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f413866%2fhow-to-execute-several-commands-after-each-other-with-one-request-to-the-termina%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

Tamil (spriik) Luke uk diar | Nawigatjuun

Align equal signs while including text over equalitiesAMS align: left aligned text/math plus multicolumn alignmentMultiple alignmentsAligning equations in multiple placesNumbering and aligning an equation with multiple columnsHow to align one equation with another multline equationUsing \ in environments inside the begintabularxNumber equations and preserving alignment of equal signsHow can I align equations to the left and to the right?Double equation alignment problem within align enviromentAligned within align: Why are they right-aligned?

Training a classifier when some of the features are unknownWhy does Gradient Boosting regression predict negative values when there are no negative y-values in my training set?How to improve an existing (trained) classifier?What is effect when I set up some self defined predisctor variables?Why Matlab neural network classification returns decimal values on prediction dataset?Fitting and transforming text data in training, testing, and validation setsHow to quantify the performance of the classifier (multi-class SVM) using the test data?How do I control for some patients providing multiple samples in my training data?Training and Test setTraining a convolutional neural network for image denoising in MatlabShouldn't an autoencoder with #(neurons in hidden layer) = #(neurons in input layer) be “perfect”?