How to create a basic script

How to create a basic script

At the next practical exercise, aimed at users more new to this Linux-based operating system, I am going to show you how to perform a simple script that will help us update repositories, update all software or even install our favorite programs with just one click and automatically.

Using this script, which we will carry out ourselves, will avoid having to type in the terminal the commands to install the different applications, programs or commands that we usually use on a regular basis.

Custom script utilities

One of the main utilities that I see for script that we will perform next, it is once we do a clean installation of Ubuntu, with only run the script we can update and install all our favorite programs without having to enter anything in the terminal.

We can also do the script With any command that we often use to avoid having to open the terminal and execute it manually, I leave everything to your imagination.

How to create a simple script

To create a simple script To execute a command such as updating the repositories, or installing our favorite programs, we will have to create a new text document with gedit and enter the following lines that I will describe

How to create a basic script

#! / Bin / bash

threw out Gimp

threw out ..within 1 sec the script starts, or closes the terminal

Sleep 1s

cd / home / user

sudo apt-get update

sudo apt-get upgrade

sudo apt-get install gimp compizconfig-settings-manager chromium-browser cairo-dock amarok vlc kolourpaint4 qbittorrent ubuntu-restricted-extras

The first line of all is the one that we have to respect since it is the one that gives the order that is an executable text file in bash and we should not modify it.

The other parts that I have marked in red are the ones that we can modify at will knowing the following:

threw out We will give it the name that we want, optional of each one and that briefly describes the script.

echo. here we can tell you how long the script to run once the terminal is open, in order to give us time to close the terminal if we do not want to install it.

Sleep the timeout for the script to run in the terminal

cd and the path where we want to install the programs by default, it is recommended to leave it as it is since this way it will install them in our user folder by default within our Home.

This basic script we would update the list of repositories, we would update all the installed software and then it would install all the programs included after the command sudo apt-get install, always leaving a space between each program.

How to create a basic script

To execute it we will only have to open Nautilus and from the option file / preferences / behavior and check the box ask every time which is within the option of Executable text files.

How to create a basic script

In this way, just by clicking twice on an executable text file, it will ask us if we want  show it with the text editor or run it directly.

More information - Ubuntu 13.04, Creating bootable USB with Yumi (in video)