How to run .sh file in Mac Terminal

A file with .sh extension is a Bash script that you can execute using the Mac Terminal. Say you have a file 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 
    -rw-r--r--  1 c2ctech  staff  36 Sep  6 12:11

    If we try to run the sh script without execution permission we will get an error.

    % ./
    zsh: permission denied: ./

    So before we can execute the script we need to add execute permissions using the command chmod +x

    chmod +x

Step 2: Running the .sh script file

    We can run the sh file by adding a ./ before the script file name.


    If you are providing an absolute path for the file, you can do that as follows,

    Execute .sh file in Mac Terminal example

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!

Buy Code2care a Coffee!

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail:

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap