Scripts in Ubuntu

Scripts in Ubuntu

Today's post is for beginners and intermediate users. Let's talk about the scripts.

Scripts are files that, once executed, fulfill orders on a computer. A bit of a messy definition, right?

Look, we can write in the terminal

sudo apt-get update

sudo apt-get upgrade

sudo apt-get install skype

We can do all these orders manually every day, but imagine we don't have time. Operating systems allow us to save these orders in a document and by executing that document in the terminal the computer would perform all these tasks without having to write anything. Furthermore, we can give an order to the computer to execute that document every day as we turn on the pc and thus we would not have to write anything. Well, that document stops being text and becomes programming. A simple programming and always framed in the specific operating system, is what we call scripts. A script does not create a program for you out of thin air but is limited to executing actions that the computer can do without the script.

So years ago we saw how when executing a file, the words appeared on our computer screen I love you it was the result of a famous virus that was based on a script in which it was ordered to write those letters on the screen.

En GNU / Linux and Ubuntu there's also scripts, and very useful scripts as you have seen in the blog posts. Today we are going to tell you how to do it own script and let you know this world that well done can help improve the relationship with our machine.

What do you need?

The list of needs is this:

  • Gedit or Nano or another text editor.
  • Know the commands available in GNU / Linux Ubuntu.
  • Have a lot of sight and patience.

But how do we make a script?

We open a new document and write

#! / bin / bash

then we write the variables that go with the name we want followed by the '=' sign and the value we want to put it. If we want to put letters we will have to put it in quotes.

Once we have set the variables we want, to execute them we will have to put the sign "$" in front of the variable. If we want to execute a command we write it in the following line and to finish the script we only have to write the word "Exit"

An example:

#! / bin / bash

var1 = "Hello, how are you?"

var2 = "I am very well"

clear

echo $ var1 $ var2

sleep -5

exit

In this script what we do is create two variables in which we distribute the text "Hi, how are you? I'm fine”, Then we clear the screen with the clear command, we publish the variables with echo and then we put the system to sleep and then finish the script. We save it with the name we want and to execute it we will have to write

exec "script name"

or give it root permissions and run it. I do not recommend the latter for clear security reasons because third-party scripts do not know what it can do.

It is simple right? Well, in this you can put Ubuntu commands like the list that appears in this blog post. Very good and with a lot of idea about what scripts to do. In a next post I will talk about making menus and operations with it for now, have a good Easter.

More information - Getting into the terminal: basic commands , Scripts for Nautilus

Image - Wikimedia


3 comments, leave yours

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.   liher said

    it's very good to start testing
    thank you very much

  2.   Ricardo Lawrence Lois said

    To run a script you don't need to give it root permissions, but rather execute permissions.

  3.   jesus said

    It does not work for me