What is the SH file format?
.sh is a common Unix shell file extension, used by bash (Bourne-again shell) and other POSIX-compatible shells. .sh files store shell scripts - sequences of commands and instructions written in shell language, saved as plain text.
.sh files are created in any text editor and are mainly used for scripts executed by a Unix shell command line. A .sh file typically begins with a shebang line - such as #!/bin/sh or #!/bin/bash - which tells the operating system which interpreter to invoke. To run a script directly, the file must be made executable with chmod +x filename.sh.
Bash is an interpreted command language and a free Unix shell distributed under the GNU license, used by default on many Linux and macOS systems. Most Unix-family systems support this shell. Bash replaced the original Bourne shell, hence the name - Bourne-again.
.sh files can also be used for saving scripts intended for other shells, such as Korn Shell, Z Shell, C Shell, or Bourne Shell. On Windows, equivalent automation is handled by batch files or PowerShell scripts. Because .sh conventionally signals POSIX shell compatibility, scripts targeting a specific shell declare their interpreter explicitly in the shebang line.
Security & safety
RISK: MEDIUMA .sh file is the Unix equivalent of running arbitrary commands: when executed it can do anything the user can - delete files, install software, exfiltrate data, or run malware. The notorious "curl URL | bash" pattern runs a remote script with no chance to inspect it. Safety rules: (1) NEVER run a .sh from an untrusted source without reading it first - it's plain text, so open it in an editor and check what it does; (2) be wary of obfuscated one-liners, base64 blobs, or scripts that pipe to sudo; (3) self-extracting installer scripts (shar/Makeself, including .run) hide a payload after the script - only run them from the official vendor. A .sh is not automatically dangerous, but it is code, so trust the source.
Format details
in a nutshellPrograms that open SH files
Technical details
deep spec| File type | Plain-text executable shell script |
| MIME type | application/x-sh |
| Shebang convention | First line declares interpreter: #!/bin/sh, #!/bin/bash, or #!/usr/bin/env bash |
| Character encoding | UTF-8 or ASCII; encoding must be supported by the target shell |
| Line endings | LF (Unix-style) required; CRLF line endings cause syntax errors on most shells |
| Execution method | Invoke with bash script.sh, or set executable bit (chmod +x) and run directly as ./script.sh |
| Comment syntax | # character; everything from # to end of line is ignored by the interpreter |
| Variable assignment | No type declaration required; VAR=value (no spaces around =); accessed as $VAR or ${VAR} |
| Exit code convention | 0 = success; any non-zero value = error; returned via exit N or inspected in $? |
| POSIX portability | Scripts written to POSIX sh standard run on bash, dash, ksh, and any conforming shell |
| Error handling flags | set -e exits on first error; set -u treats unset variables as errors; set -o pipefail catches pipe failures |
| Platform support | Native on Linux and macOS; available on Windows via WSL, Git Bash, or Cygwin |
| Primary interpreter | Bash (GNU Bourne-Again Shell); also dash, ksh, or zsh depending on the shebang line |
| Script debugging | set -x enables trace mode, printing each command before execution; bash -n checks syntax without running |
| Released | 1979 (Bourne shell, Unix V7); POSIX shell standardized; Bash 1989 |
| Open standard | Yes · royalty-free |
| Specification | pubs.opengroup.org |
SH conversions
Community Q&A
asked by usersNo questions yet - be the first to ask about SH files.