What Is a .SH File? (.sh, .bash, .zsh, .command)
A .sh file is a shell script: a plain-text list of commands for a Unix shell such as bash or zsh, run on Linux, macOS and Windows through WSL or Git Bash. Shell scripts automate installs, builds, backups and server tasks. They run with your permissions, so read one before running it.
- Extension
- .sh, .bash, .zsh, .command
- Full name
- Shell Script
- Type
- Code and web file
- MIME type
- application/x-sh
About SH files
A script usually starts with a shebang line such as #!/bin/bash or #!/usr/bin/env bash that tells the system which shell to use. To run it, either call the shell (bash script.sh) or make it executable with chmod +x script.sh and run ./script.sh. macOS uses zsh as its default shell since Catalina, but bash scripts still run with bash.
Scripts edited on Windows can break on Linux and Mac because of Windows line endings, causing errors like /bin/bash^M: bad interpreter. Converting the file to LF line endings (VS Code shows the setting in the status bar) fixes it. On a Mac, a .command file is a shell script that opens in Terminal when double-clicked.
Many install instructions ask you to pipe a downloaded script straight into the shell (curl ... | sh). That runs whatever the server sends, with your permissions or with sudo if asked. Prefer installers from the project's official domain, download and read the script first when you can, and never run scripts from forum posts or messages you do not trust.
What SH files are used for
- Installing and setting up software and developer environments
- Build, test and deploy scripts in code projects
- Server maintenance, backups and cron jobs
- Automating repetitive terminal commands
How to open a .sh file
Mac
To read it, open with TextEdit or VS Code. To run it, open Terminal and type bash script.sh.
Linux
Run bash script.sh, or chmod +x script.sh then ./script.sh. Any editor opens it for reading.
Windows
Open it in Notepad or VS Code to read. To run it, use WSL (Windows Subsystem for Linux) or Git Bash.
How to convert a .sh file
To use a shell script on Windows without WSL, rewrite it as a PowerShell (.ps1) or batch (.bat) script; there is no reliable automatic converter.
If a script fails with ^M errors, convert its line endings from CRLF to LF in VS Code or with dos2unix.
Renaming .sh to .bat or .exe does not make it run on Windows.
Changing the extension in the file name does not convert the file. See how to change a file extension for when renaming is safe.
Naming and renaming SH files
- Use lowercase names with hyphens and a verb (setup-dev.sh, backup-db.sh) so tab completion and listings stay readable.
- Keep project scripts in a scripts/ folder and document them in the README rather than encoding usage in long file names.
- The extension is optional on Linux and macOS; the shebang decides the interpreter, but .sh helps editors and people recognize the file.
Renaming lots of .sh files? Use the free online bulk renamer for patterns and numbering, or try File Renamer AI to name each file from what is inside it.
Related file types
A .bat file is a Windows batch script: a plain-text list of Command Prompt commands that run one after another when you double-click it. Batch files automate tasks such as copying files, launching programs or changing settings. The .cmd extension works almost the same. They run with your permissions, so only run trusted ones.
A .ps1 file is a PowerShell script, the file extension Microsoft uses for scripts written in its PowerShell command-line language. It contains plain text commands that automate Windows and server administration tasks. Double-clicking a .ps1 opens it in Notepad rather than running it, a deliberate safety measure.
A .py file is a Python script: a plain text file of Python source code that the Python interpreter runs. It is used for automation, data analysis, web back ends, machine learning and teaching. You can open and read any .py file in a text editor, but running one requires Python to be installed.
A .yaml or .yml file is a plain-text data file in YAML, a human-friendly format that uses indentation instead of brackets to structure lists and key-value pairs. It is the standard for configuration in Docker Compose, Kubernetes, GitHub Actions, Ansible and many apps. Both extensions mean exactly the same thing.
Frequently Asked Questions
How do I run a .sh file?
In Terminal, type bash script.sh, or make it executable with chmod +x script.sh and run ./script.sh. On Windows use WSL or Git Bash.
Is a .sh file safe?
It runs any commands it contains with your permissions, so read it first and only run scripts from trusted sources.
Why do I get bad interpreter: /bin/bash^M?
The file has Windows line endings. Convert it to LF line endings and run it again.
Can I run a shell script on Windows?
Yes, through WSL or Git Bash; Command Prompt and PowerShell cannot run it directly.