As Clausi pointed out, yyp!!sh
yanks (copies) the current line to the register, pastes that line below the original one, and replaces the bottom one with the output of the command.
To save keystrokes you can map this action by adding the next line in the ~/.vimrc
file:
map <F5> yyp!!sh<CR><Esc>
This way everytime F5 is pressed in command mode, the line will be executed and the result will be shown below the line.
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.
Best Answer
This is called a script.
Right click on the text file, select properties, select permission, mark the "Let this file be executed" text box. Now you can execute it just by double clicking on the file.
You can also do it from the console like this:
Or change the permissions and afterwards execute it: