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.
How to open 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
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.
.sh file signature (magic bytes)
Programs recognise a .sh file by the bytes at the start of the file, not by its name. These are the signatures for SH.
| Hex signature | Offset | 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: