How to Make a Bash Script Executable

Posted by Chaitanya Shahare on Tue, Nov 22, 2022

Bash scripts can be used to automate bash shell commands, they have the extention .sh. I personally use these to do some repetitive tasks like deploying a new post to this site.

To run a bash script you need to use the following command syntax in the command line:

sh ./address/scriptName.sh

But the script is not executable by itself, to make it executable follow the following steps

1. Add approriate shebang

For bash add the following shebang at the top of the script

#!/bin/bash

2. Run the chmod command for the file

Go to the directory containing the script and use the following command

chmod u+x scriptName.sh

3. Run the script

To run the script in the same directory

./scriptName.sh

For any other directory

/address/scriptName.sh