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.
zsh: permission denied: ./script.sh
So before we can execute the script we need to add execute permissions using the command chmod +xExample:
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:
If you are providing an absolute path for the file, you can do that as follows,
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!
Facing issues? Have Questions? Post them here! I am happy to answer!
- How to Display Analog Clock on Mac Menu Bar
- Shutdown Mac Terminal Command
- How to know the Serial Number of MacBook on macOS Ventura 13.0
- macOS: Remove Desktop or Documents Folder from iCloud Drive Syncing
- [fix] How to Show file extensions on all files on Mac
- How to install Zoom Add-in to Outlook (Mac)
- How to turn off Stage Manager - macOS Ventura
- Fix - Xode - Internal logic error: Connection was invalidated
- How to do calculations in Mac Terminal
- How to delete a Page in Microsoft Word File on Mac (macOS)
- How to Refresh Mac Desktop
- How to install Java on macOS [Big Sur]
- How to Disable Mac Terminal Bell Sound
- Installing MongoDB on Linux/Unix/macOS/Ubuntu
- How to Uninstall Brew on Mac
- Find your macOS version
- Change TextEdit File Encoding
- AppleScript Example with TextEdit
- How to install homebrew (brew) on M1 Mac
- How to Find File and Directory Size in Mac Terminal
- How to open new tab in Sublime Text Editor [macOS]
- How to list all users in Mac Terminal
- Turn off Auto-Capitalization on macOS Ventura 13
- How to check Command Line Tools Version [Updated for Ventura]
- Change Current User Password using Mac Terminal Command
- remove div vertical scroll - Html
- 70+ HTTP Error Codes CheatSheet - Html
- Clearing the Cache in Firefox Web Browser - HowTos
- How to install ddtrace - Datadog tracing library for Python - Python
- Word count in Sublime Text Editor - Sublime-Text
- How to Force Quit Microsoft Excel Application on Mac - Microsoft
- Opening mac Terminal - MacOS
- How to pretty print HTML using Java Code - Html