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?
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.
Comments