What is a .sh file?
Shell Script · Code and data · Unix · 1970s
An SH file is a shell script: a plain-text list of commands that a Unix-style shell (bash, zsh) runs in order. It is how tasks are automated on Linux and macOS. Because it runs commands, read one before you run it.
What is a .sh file used for?
A shell script is just text, a sequence of the same commands you could type into a terminal, saved so they run together. The first line is often a shebang such as #!/bin/bash that names the shell to use.
Scripts drive installers, build steps and everyday automation across Linux and macOS. On Windows they run under WSL or Git Bash.
A .sh does nothing until it is executed. To run one you usually make it executable (chmod +x script.sh) and then run ./script.sh, or invoke it with bash script.sh.
Because running it executes real commands, always open an unfamiliar script in a text editor and read it first.
What opens a .sh file?
The .sh format opens in the following apps, grouped by operating system. If one app does not work, try another from the same list.
Windows
- A text editor (to read/edit)
- WSL or Git Bash (to run)
macOS
- A text editor (to read/edit)
- Terminal (to run)
Linux
- A text editor (to read/edit)
- Terminal (to run)
Web
- Not applicable
Open a .sh file step by step
- Confirm the file really is a .sh. Drop it into the WhatFileType identifier, which reads its signature in your browser without uploading anything.
- On Windows, open it with A text editor (to read/edit) or WSL or Git Bash (to run).
- On Mac, use A text editor (to read/edit) or Terminal (to run).
- On Linux, try A text editor (to read/edit) or Terminal (to run).
- Still stuck? Convert the .sh to Not convertible, which opens more widely.
Why can't I open my .sh file?
Almost always because no installed app understands SH. Install one of the apps above, or convert the file to a format your existing software already reads. If double-clicking opens the wrong program instead of nothing at all, the file association is set to the wrong app rather than the file being broken.
The other possibility is that the file is not really a .sh at all. Drop it into the file identifier to check it by its bytes instead of its name. Nothing is uploaded.
How to convert a .sh file
You can convert a .sh file to Not convertible using a conversion tool or the export menu of an app that opens it.
What is the .sh file signature (magic bytes)?
A .sh file may start with the hex bytes 23 21, which read as #! in ASCII. Those bytes are a hint rather than a guarantee, so SH cannot be identified by its header alone.
These are the documented signatures for SH.
| Hex signature | Offset | ASCII | Note |
|---|---|---|---|
| 23 21 | 0 | #! | '#!' shebang line, commonly #!/bin/bash (common, not required) |
See the full magic-numbers reference for every format.
Frequently asked questions
What is a .sh file?
An SH file is a shell script: a plain-text list of commands that a Unix-style shell (bash, zsh) runs in order. It is how tasks are automated on Linux and macOS. Because it runs commands, read one before you run it.
How do I run a .sh file?
In a terminal, make it executable with chmod +x script.sh and run ./script.sh, or run it directly with bash script.sh. On Windows, use WSL or Git Bash.
Is it safe to run a shell script?
Only if you trust it. A script runs real commands, so read it in a text editor first. If you did not write it and cannot vet it, do not run it.
Related formats
Sources
Details on this page were checked against authoritative references. How sources are ranked and what is deliberately left out is set out in the methodology.