.sh File Extension
.sh file contains, how to open and check shell scripts safely, how Poly supports them, and how shell dialects differ. File extension details for .sh
Full Support| File type | Shell script |
|---|---|
| MIME type | |
| Encoding | Plain text, commonly UTF-8; Unix LF line endings are the most portable |
| Operating systems | Linux, macOS, Windows with WSL or a compatible shell |
| Opens with | Visual Studio Code, GNU Bash, Zsh, Any text editor |
| Poly support | Yes. Poly recognizes .sh files as shell scripts and provides code-aware text features. |
| Indexed by Poly | Yes. Poly indexes readable source for exact and semantic search without running it. |
| Preview in Poly | Yes. .sh files open in Poly's code-friendly text viewer with syntax highlighting. |
| Poly agent | Yes. The Poly agent can read and reason about the available script without executing it. |
What kind of file is a .sh?
A .sh file is a plain-text shell script: a sequence of commands intended for a command-line shell. POSIX defines a shell script as a file containing shell commands, but the suffix does not identify one exact language.1 A file might use portable POSIX sh, Bash features, Zsh syntax, or commands that exist only on a particular operating system.
There is no fixed magic number. Many scripts begin with a shebang such as #!/bin/sh or #!/usr/bin/env bash, which helps an operating system select an interpreter. Scripts can also omit both the shebang and the .sh suffix and still run when passed directly to a shell.2
The de facto text/x-shellscript MIME type is not registered by IANA. Linux MIME databases commonly use application/x-shellscript instead, so software may classify the same script differently.34
.sh does not make its contents valid shell code. Renaming a Bash script does not translate Bash-specific syntax into portable POSIX sh.How do I open a .sh on my computer?
Open an .sh file with any text editor on Linux, macOS, or Windows. Visual Studio Code and other code editors add syntax highlighting. To run a trusted script, use the interpreter it expects, such as bash setup.sh or sh task.sh. On Windows, that usually means Windows Subsystem for Linux, Git Bash, or another installed Unix-compatible shell.
Inspect an unfamiliar script before running it. Check its shebang, redirects, downloads, privilege changes, and commands that modify files. A syntax check such as bash -n setup.sh can catch Bash parsing errors without executing commands, but it does not prove the script is safe or that it will work in another shell.5
Poly support for .sh
Poly opens .sh source in a code-friendly text viewer and indexes its readable contents for exact and semantic search. You can find a known command or search by the task a script appears to perform.
The Poly agent can summarize the script, explain visible control flow, and reason about changes. Poly does not execute it. Runtime variables, sourced files, installed commands, credentials, and network responses are available only when you provide that context.
History of .sh
The suffix comes from sh, the traditional Unix shell command name. The Bourne shell appeared as sh in Seventh Edition Unix, and later shells retained varying degrees of compatibility.6 POSIX standardized a shell command language, while Bash, Zsh, KornShell, and other shells added their own features.
Unix execution does not require a filename extension, so .sh has always been a convention rather than part of the executable-file mechanism. It remains useful to people, editors, and file classifiers because it signals that a file probably contains shell commands.
Working with .sh and alternatives
Choose the interpreter from the script's actual syntax, not its suffix:
| Goal | Better choice | Main tradeoff |
|---|---|---|
| Run across POSIX systems | POSIX sh syntax | Fewer shell-specific conveniences |
| Use arrays or other Bash features | Bash with an explicit shebang | Bash must be installed |
| Automate Windows-native tasks | PowerShell script | Different language and tooling |
| Document commands for a person | Markdown or plain text | Not directly executable |
Keep scripts as UTF-8 text when possible and use Unix LF line endings for broad shell compatibility. Test with the actual interpreter and operating systems you support. A .sh name alone cannot guarantee portability, safety, or correctness.
Footnotes
- The Open Group. POSIX.1-2024 Definitions: Shell Script. ↩
- The Open Group. POSIX.1-2024 Shell Command Language. The shell can read commands from a file, while interpreter-line behavior is system-dependent. ↩
- Internet Assigned Numbers Authority. Media Types Registry. The text registry does not include
x-shellscript. ↩ - freedesktop.org shared-mime-info project, mirrored by Debian.
application/x-shellscriptMIME Database Definition. ↩ - GNU Project. Bash Reference Manual: Invoking Bash. The
-noption reads commands and checks syntax without executing them. ↩ - GNU Project. Bash Reference Manual: What Is Bash?. The manual traces Bash to Stephen Bourne's
shin Seventh Edition Unix. ↩