.sh File Extension

Learn what a .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 typeShell script
MIME type
EncodingPlain text, commonly UTF-8; Unix LF line endings are the most portable
Operating systemsLinux, macOS, Windows with WSL or a compatible shell
Opens withVisual Studio Code, GNU Bash, Zsh, Any text editor
Poly supportYes. Poly recognizes .sh files as shell scripts and provides code-aware text features.
Indexed by PolyYes. Poly indexes readable source for exact and semantic search without running it.
Preview in PolyYes. .sh files open in Poly's code-friendly text viewer with syntax highlighting.
Poly agentYes. 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

Renaming a text file to .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

Shell scripts are readable text and executable instructions. Opening one in an editor is safe; running it can change files, install software, access credentials, or contact network services with your permissions.

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:

GoalBetter choiceMain tradeoff
Run across POSIX systemsPOSIX sh syntaxFewer shell-specific conveniences
Use arrays or other Bash featuresBash with an explicit shebangBash must be installed
Automate Windows-native tasksPowerShell scriptDifferent language and tooling
Document commands for a personMarkdown or plain textNot 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

  1. The Open Group. POSIX.1-2024 Definitions: Shell Script.
  2. The Open Group. POSIX.1-2024 Shell Command Language. The shell can read commands from a file, while interpreter-line behavior is system-dependent.
  3. Internet Assigned Numbers Authority. Media Types Registry. The text registry does not include x-shellscript.
  4. freedesktop.org shared-mime-info project, mirrored by Debian. application/x-shellscript MIME Database Definition.
  5. GNU Project. Bash Reference Manual: Invoking Bash. The -n option reads commands and checks syntax without executing them.
  6. GNU Project. Bash Reference Manual: What Is Bash?. The manual traces Bash to Stephen Bourne's sh in Seventh Edition Unix.
© Poly Corp. 2026