Linux and Networking

Linux and Networking

4.1. Your first shell script

First open a document and write the following text:

 

#!/bin/bash

echo ‘Hello hello’

Save it and call the file script.sh

 

The next step is to give it execute permission and run the script from the terminal. From a terminal and in the directory where the script is, execute the following commands:

 

$chmod +x script.sh

$ ./script.sh

 

If everything works correctly, the following should appear on the screen:

 

$chmod +x script.sh

$ ./script.sh

Hello hello

 

And why does that come out? We are going to comment line by line on the previous script

 

#!/bin/bash

echo ‘Hello hello’

 

In the first line we tell the system that the command interpreter it has to use to execute the script is bash located at the /bin/bash address. This line is special because it has the characters #!. These characters will only appear in this first line of the script.

 

Proposed exercise.

Copy and execute the previous exercise. Check that your script works correctly and display “Hello hello” on the screen.

The Demeter Project