Next Previous Contents

2. Very simple Scripts

This HOW-TO will try to give you some hints about shell script programming strongly based on examples.

In this section you'll find some little scripts which will hopefully help you to understand some techniques.

2.1 Traditional hello world script

          #!/bin/bash          
          echo Hello World    
        

This script has only two lines. The first indicates the system which program to use to run the file.

The second line is the only action performed by this script, which prints 'Hello World' on the terminal.

If you get something like ./hello.sh: Command not found. Probably the first line '#!/bin/bash' is wrong, issue whereis bash or see 'finding bash' to see how sould you write this line.

2.2 A very simple backup script

        #!/bin/bash          
        tar -cZf /var/my-backup.tgz /home/me/
        

In this script, instead of printing a message on the terminal, we create a tar-ball of a user's home directory. This is NOT intended to be used, a more useful backup script is presented later in this document.


Next Previous Contents

Hosting by: Hurra Communications Ltd.
Generated: 2007-01-26 17:57:59