Making a BASH script executable (Raspberry Pi)

There were often times when I found myself typing the same commands into the terminal on my Raspberry Pi and I with my knowledge of scheduling Python (.py) files to run via CRON I decided to start running my regular terminal commands as scripts.

A BASH executable script is basically a text file saved with the file extension .sh and with a sha-bang line at the very top that reads:

#!/bin/bash

With the file saved close the text editor and open a terminal window. Navigate to the folder containing the file and then type:

chmod +x bash_file_name.sh

chmod +x
chmod +x

Replacing “bash_file_name.sh” with the name of your BASH file’s name.

This command changes the file attributes so that it can be run as an executable. Once executable it can be run via the Terminal by typing:

./bash_file_name.sh

./bash_file_name
./bash_file_name

 

 

2 thoughts on “Making a BASH script executable (Raspberry Pi)

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.