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
![Execute .sh file in Mac Terminal example Execute .sh file in Mac Terminal example](https://code2care.org/q/run-sh-file-mac-terminal/images/Execute .sh file in Mac Terminal example.jpg)
Facing issues? Have Questions? Post them here! I am happy to answer!
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: rakesh@code2care.org
- Fix: grunt: command not found (Mac/Windows)
- AppleScript Example with TextEdit
- How to copy Password of Wifi on your Mac
- Install OpenJDK Java (8/11/17) versions using brew on Mac (Intel/M1/M2)
- How to check if a port is in use using terminal [Linux or macOS]
- Cut, Copy and Paste Keyboard Shortcuts on Mac Keyboard
- [macOS] NetBeans IDE cannot be installed. Java (JRE) found on your computer but JDK XX or newer is required.
- How to Remove Widgets from macOS Sonoma 14 Desktop
- Turn off Auto-Capitalization on macOS Ventura 13
- How to Go To /usr/local/bin on Mac Terminal?
- How to Open TextEdit on Mac
- Mac: How to Open Android Studio from Terminal
- How to change the default location of Mac Screenshot
- Display Seconds in Digital Clock on Mac Menu Bar [macOS]
- How to install homebrew (brew) on M1 Mac
- Must Know Homebrew Commands for Mac/Linux Users
- Steps to Uninstall Roblox on Mac (macOS)
- How to change the System Settings Sidebar icon size Mac Ventura 13
- How to set Out Of Office (OOO) on Outlook for Mac [Updated 2023]
- Trigger Notification Center Message using Mac Terminal Command
- [fix] macOS Ventura - Python3 xcrun: error: invalid active developer path missing xcrun at CommandLineTools
- How to Install Rust Language on Mac (macOS)
- How to minimize all Windows in Mac
- Display ls command file sizes in KB (kilobytes) MB (megabytes) or GB (gigabytes) [Linux/macOS]
- How to make TextEdit the default text Editor on Mac
- [Solved] Error launching studio - Android-Studio
- How to install iTerm2 - Terminal alternative for Mac - MacOS
- [Fix] Error 1020 Cloudflare: Access was denied - HowTos
- How to unpair an Apple Watch with an iPhone - iOS
- Queue Implementation in Java with Examples - Java
- How to Replace delimiter with new line in Notepad++ - NotepadPlusPlus
- Fix: Ubuntu (Linux) - bash: sudo: command not found error - Ubuntu
- How to remove or uninstall Java from Ubuntu using apt-get - Linux