A script is simply a text file containing one or more instructions that are executed when the script is run.
There is no specific extension for a script, as it can be written in several ways. For example, Python code can also be treated as a script, but of course it requires Python to be installed in order to run.
In the example below, we will create a text file with the “.sh” extension that simply prints “Hello World!” in the terminal. No software needs to be installed, because we will be using the capabilities of the shell.
With that said, connect to your Raspberry Pi via SSH or, if you prefer, launch the “Terminal” directly from the Raspberry Pi’s graphical interface.
Then type:
sudo nano /home/pi/myScript.sh
and enter the following in the file:
#!/bin/bash
echo Hello World!
Save the file by pressing CTRL+O and close the nano text editor with CTRL+X.
Change the permissions of the file you just created by typing:
sudo chmod 777 /home/pi/myScript.sh
Now all that’s left is to test the script by typing:
sh /home/pi/myScript.sh
If you see a line reading “Hello World!” appear in the terminal, your script works perfectly.
Enjoy!
