How to create a basic script

How to create a basic script

At 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)


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   Someone said

    Is this also applicable on the cinnarch Gnome distro or any other distro or only on ubuntu?

    1.    Francisco Ruiz said

      This would work for any Ubuntu or Debian based distro.
      On 16/04/2013 01:22, «Disqus» wrote:

  2.   Jose Luis said

    Very interesting.

    Where could we add the necessary repositories to the script, such as medibuntu or jdownloader?

    Thank you very much

    1.    Francisco Ruiz said

      On a new line just above sudo apt-get update

      2013/4/16

  3.   gavg712 said

    Hello, I liked that post. I would like to know if a script can be made to connect to a Webdav server (actually a hard drive connected directly to the network) using nautilus.

    Does anyone know if it is possible?

    1.    Francisco Ruiz said

      With this type of basic script you can execute any command from the terminal, you just have to put it at the end of the text file. I have not tried it but I think it would work.
      Greetings.

      2013/4/16

  4.   Felipe said

    I can run a sh file so I don't have to run from terminal
    because I do it from the terminal like this
    cd games / pk
    chmod + x Pk.sh
    sh Pk.sh
    and the application is executed, it will be useful, could you recommend something to be able to execute it from the launcher icon thanks

  5.   Jon said

    Thank you Francisco, it has been a great help; For those of us who come from MsDos, Win95-98-98_2ª, Xp, Win7, it helps us to immerse ourselves in Linux (I like it more and more).
    Some more points:
    I have Linux Mint 17.1 Rebecca Cinamon, to execute the file, it has to be in the path (path, path or executable directory recognition), having it in our home is enough ~ (alt gr + ñ), and you have to change the attributes to the file , I make it all free to read and write and select "allow the file to run as a program", the extension I put is "sh"; chip change, from bat to sh 🙂