What is an SH File?
An SH file is a shell script: a plain-text file of commands for a Unix shell such as Bash, sh or Zsh. Shell scripts automate tasks on Linux and macOS, from installing software to backups and server setup. The first line, called the shebang (for example #!/bin/bash), tells the system which shell should run the script.
You can run an SH file with bash script.sh, or make it executable with chmod +x script.sh and start it with ./script.sh. On Windows, shell scripts run in WSL, Git Bash or Cygwin.
Download SH Sample Files
Below are three short Bash scripts.
SH Sample File Details
| Sample | What it does | Lines | File size |
|---|---|---|---|
| Sample1.SH | Prints three lines with echo, echo -n and echo -e | 4 | 91 bytes |
| Sample2.SH | Prints a welcome message using variables, $USER and $HOSTNAME | 12 | 225 bytes |
| Sample3.SH | Counts from 0 to 4 in a while loop | 8 | 78 bytes |
All three start with #!/bin/bash and use Windows (CRLF) line endings. That makes them a realistic test case, because Bash on Linux and macOS does not accept those line endings: running ./sample-1.sh fails with a “bad interpreter” error that mentions /bin/bash^M, and sample 3 stops with a syntax error. Convert the line endings first, then run the script:
# Remove the Windows carriage returns (or use dos2unix)
tr -d '\r' < sample-3.sh > sample-3-fixed.sh
$ bash sample-3-fixed.sh
Number: 0
Number: 1
Number: 2
Number: 3
Number: 4
What You Can Test With These SH Files
- Line-ending handling: CRLF scripts in editors, Git (
core.autocrlf) and tools such as dos2unix. - Linters: ShellCheck reports the carriage returns in these files.
- Code editors: syntax highlighting for shell scripts.
- CI and deployment pipelines: scripts written on Windows and run on Linux.
- Upload filters: detecting or blocking executable scripts.
How to Check and Run an SH File
# Check the syntax without running the script
bash -n sample-2.sh
# Lint with ShellCheck
shellcheck sample-1.sh
# Make a script executable and run it (after fixing the line endings)
chmod +x sample-3-fixed.sh
./sample-3-fixed.sh
SH vs Other Script Files
| Script type | Extension | Runs on |
|---|---|---|
| Shell script | .sh | Linux, macOS and WSL |
| Batch file | .bat | Windows Command Prompt |
| PowerShell script | .ps1 | Windows, Linux and macOS with PowerShell |
| Python script | .py | Any system with Python |
| Perl script | .pl | Any system with Perl |






