BASH scripts are small files containing lines of commands. These little scripts are very useful. The following are a few examples …
- BASH scripts can contain any command you can run from a shell. This makes it very,very powerful.
- You can use it to set up/configuring your Raspberry Pi (…or any Linux-based system for that matter)
- To run special tasks at start-up or before shut-down.
- For updating text files or databases. It can do loops and IF statements… Basically anything you can think of automating.
Lets start….
- Start by opening a terminal/shell window .
- First we will create a folder that we can play with.
1 2 3 4 5 |
cd / mkdir testfolder cd testfolder |
- Next we will download an example BASH script and open it up. (The wget is very useful for downloading files from the internet)
1 2 3 4 |
sudo wget http://blog.protoneer.co.nz/downloads/test.sh sudo nano test.sh |
The Nano app is a terminal based text file editor that’s very useful for making changes to BASH script files.
The above BASH script echos text to the terminal screen.
To run it enter the following command:
1 2 3 |
bash test.sh |
The above script is only a simple example of how BASH scripts work but it can do much more than just echoing stuff.