A file with .sh extension is a Bash script that you can execute using the Mac Terminal. Say you have a file script.sh and you want to execute it, follow the below steps.
Step 1: Make sure the sh file has execute permissions
By default the sh file will not have execute permissions, we can check that using the ls command.
% ls -l script.sh
-rw-r--r-- 1 c2ctech staff 36 Sep 6 12:11 script.sh
If we try to run the sh script without execution permission we will get an error.
% ./script.sh
zsh: permission denied: ./script.sh
So before we can execute the script we need to add execute permissions using the command chmod +x
Example:chmod +x script.sh
Step 2: Running the .sh script file
We can run the sh file by adding a ./ before the script file name.
Example:./script.sh
If you are providing an absolute path for the file, you can do that as follows,
/Users/c2ctechtv/Desktop/script.sh

This is not an AI-generated article but is demonstrated by a human on an M1 Mac running macOS Sonoma 14.0.
Please support independent contributors like Code2care by donating a coffee.
Buy me a coffee!

Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!