Running a .sh to execute multiple commands

Brendon

I was curious how I would go about running multiple commands via shell script.

For example, just to try it out, I'd like to be able to connect a .desktop to a .sh that will run all the update codes so I don't have to type it out. I know how to execute a single command via a .sh, not multiple.

Any way?

Wilf

Simple really - you need to separate the commands. For instance this:

#!/bin/bash
sudo apt-get update
sudo apt-get upgrade

will update the package lists, and then the packages. Another possibility is this (probably better, as the && will only allow the upgrade command to run if the update exits successfully):

#!/bin/bash
sudo apt-get update && sudo apt-get upgrade

This should run the commands for updating the list of packages and then the package themselves. This would need to be saved into a text file (e.g. updatescript in the home directory). You can then make it executable by running:

 chmod +x ./updatescript

or by right clicking on the file and making it executable in its properties:

and run it with this in terminal:

 ./updatescript

Note(s):

There is an option (-y) available that can be used with the upgrade command so it does not prompt before upgrading the packages. It is a good idea to check what apt-get is doing before it upgrades the packages, as it may/will do something stupid or something you don't want it do. More info on options like this can be found by running man apt-get.

This also means it is more ideal to use the terminal to run the script, as you can check what it is updating, and then run it. If you want a GUI way to run the updates, use the software-center as that it is what it is for.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to execute mysql commands in sh

From Dev

Docker - Cannot execute multiple docker run commands from same .sh file

From Dev

Execute loop while commands is running

From Dev

Running multiple commands simultaneously

From Dev

Running multiple commands in a if statement

From Dev

Execute multiple commands after [ test

From Dev

Delphi - CreateProcess - Execute multiple commands

From Dev

Execute multiple commands after [ test

From Dev

execute multiple commands after ssh

From Dev

Running remote cqlsh to execute commands on Cassandra Cluster

From Dev

Quickly execute commands without running out of memory

From Dev

Running multiple commands for npm test

From Dev

Running multiple shell commands with wildcards

From Dev

running multiple commands in a batch file

From Dev

Running multiple commands with su in Bash

From Dev

Running Multiple Line Commands with Python

From Dev

How to pass in multiple arguments to execute with .sh script

From Dev

How to execute multiple .sh files in different directories using *.sh

From Dev

sh -c irrationality and programmatically determining and running Linux builtin commands

From Dev

pass multiple commands for cmd to execute as one block

From Java

Execute combine multiple Linux commands in one line

From Dev

Execute multiple sage commands from php script

From Dev

How to execute multiple CLI commands in a python script?

From Dev

Execute multiple SQL commands at once on R

From Dev

Have puppet conditionally execute multiple commands

From Dev

execute multiple commands in cmd using java

From Dev

Gradle -- execute multiple commands from task

From Dev

execute multiple commands on console through unix shell

From Dev

How to execute multiple commands remotely on few servers?

Related Related

  1. 1

    How to execute mysql commands in sh

  2. 2

    Docker - Cannot execute multiple docker run commands from same .sh file

  3. 3

    Execute loop while commands is running

  4. 4

    Running multiple commands simultaneously

  5. 5

    Running multiple commands in a if statement

  6. 6

    Execute multiple commands after [ test

  7. 7

    Delphi - CreateProcess - Execute multiple commands

  8. 8

    Execute multiple commands after [ test

  9. 9

    execute multiple commands after ssh

  10. 10

    Running remote cqlsh to execute commands on Cassandra Cluster

  11. 11

    Quickly execute commands without running out of memory

  12. 12

    Running multiple commands for npm test

  13. 13

    Running multiple shell commands with wildcards

  14. 14

    running multiple commands in a batch file

  15. 15

    Running multiple commands with su in Bash

  16. 16

    Running Multiple Line Commands with Python

  17. 17

    How to pass in multiple arguments to execute with .sh script

  18. 18

    How to execute multiple .sh files in different directories using *.sh

  19. 19

    sh -c irrationality and programmatically determining and running Linux builtin commands

  20. 20

    pass multiple commands for cmd to execute as one block

  21. 21

    Execute combine multiple Linux commands in one line

  22. 22

    Execute multiple sage commands from php script

  23. 23

    How to execute multiple CLI commands in a python script?

  24. 24

    Execute multiple SQL commands at once on R

  25. 25

    Have puppet conditionally execute multiple commands

  26. 26

    execute multiple commands in cmd using java

  27. 27

    Gradle -- execute multiple commands from task

  28. 28

    execute multiple commands on console through unix shell

  29. 29

    How to execute multiple commands remotely on few servers?

HotTag

Archive