How to Make a Shell Script Executable on the Raspberry Pi

Command not found? No problem.
Zach Zach (248)
1 minute

If you've ever tried running a shell script, only to get a command not found error, it probably means your shell script isn't executable:

sudo ./

This very short guide will show you how to make a shell (.sh) script executable on your Raspberry Pi. This assumes your Pi is running Raspberry Pi OS or some other Linux/Unix-based operating system.

Posted in these interests:
h/pi253 guides
h/linux41 guides

Navigate to the path of the directory where the file is:

cd ~/some/directory

You can confirm that the file is not executable by running ls -la, and observing there's no x (for executable):

-rw-r--r--  1 pi pi   684 Dec 16 17:28

To make the script executable, use the chmod command:

sudo chmod +x

If you run ls -la, you'll see the file is now executable:

-rwxr-xr-x  1 pi pi   684 Dec 16 17:28

You'll now be able to execute the script successfully:

sudo ./

It's worth mentioning that the file doesn't have to be executable to run it. You can also use sudo sh, but making it executable is handy in order to execute the script directly.

Taking control of your Pi is easy!
Ash Ash (362)

Learning how to navigate your Raspberry Pi can be tricky—but it doesn't have to be! We've comprised a list of the most common Raspberry Pi commands. Not sure where to start?