What is MIME type "text/x-sh"?

A MIME type is a string that tells browsers and other tools how to handle a particular kind of file.

text/x-sh is a MIME type for plain text files that contain shell commands. These files run on Unix-like systems using shell interpreters. They let you automate system tasks and run command sequences easily.

Key facts:
It is common to see it used by files like SH and BASH scripts. Other examples include web server files such as CGI and FCGI. Files for other shell variants appear as CSH, TCSH, or ZSH.

Sometimes, related files used for specific tasks also adopt this MIME type. For instance, configuration or session files like GITIGNORE or Gentoo package scripts like EBUILD and ECLASS may be handled similarly. Other specialized files include BATS, NU, SH-SESSION, or even additions like SH.IN, TMUX, TRIGGER, and ZSH-THEME.

For more details on shell scripting, see Shell Script on Wikipedia.

Associated file extensions

Usage Examples

HTTP Header

When serving content with this MIME type, set the Content-Type header:


    Content-Type: text/x-sh    
  

HTML

In HTML, you can specify the MIME type in various elements:


    <a href="file.dat" type="text/x-sh">Download file</a>    
  

Server-side (Node.js)

Setting the Content-Type header in Node.js:


    const http = require('http');    
    
    http.createServer((req, res) => {    
      res.setHeader('Content-Type', 'text/x-sh');    
      res.end('Content here');    
    }).listen(3000);    
  

Associated file extensions

FAQs

Why does my browser download .sh files instead of running them?

Browsers are designed to display content or download files, not execute system commands. Since text/x-sh files contain server-side instructions (like BASH or ZSH), browsers treat them as plain text or downloadable objects for security reasons. To run the script, you must execute it in a terminal on a Unix-based system.

How do I configure Apache to serve shell scripts as text?

To allow users to view the source code of your scripts, add the MIME type to your Apache configuration or .htaccess file. Use the directive AddType text/x-sh .sh .bash. This tells the server to send the file as a readable script rather than trying to execute it as a CGI program.

Is text/x-sh the same as application/x-sh?

They are often used interchangeably, but text/x-sh emphasizes that the content is human-readable source code. The text/ prefix suggests the file can be opened in a standard text editor, while application/ might imply it is intended for execution or binary processing. Both are non-standard (x-) types, but text/x-sh is very common for SH files.

Can I run text/x-sh files on Windows?

Windows does not natively understand Unix shell scripts; it uses .bat or .ps1 files instead. However, you can run text/x-sh files on Windows using compatibility layers like the Windows Subsystem for Linux (WSL), Git Bash, or Cygwin. These tools provide the necessary interpreters (like bash or sh) to execute the commands.

What are the security risks of text/x-sh files?

These files contain executable commands that can modify files, install software, or change system configurations. Never execute a command or script downloaded from the internet without inspecting the code first. If a web server is misconfigured, it might accidentally expose sensitive logic inside a CGI script by serving it as text/x-sh instead of running it.

How do I make Nginx handle shell scripts correctly?

In Nginx, you can define the MIME type in the mime.types file or within a location block. Add the line types { text/x-sh sh bash; } to ensure the server identifies the files correctly. If you intend to execute the script (via FastCGI), you need a different configuration involving a backend processor, not just a MIME type assignment.

Why do some configuration files like .gitignore use this MIME type?

Although .gitignore files are not executable scripts, they share the same syntax highlighting and comment structure (using #) as shell scripts. Editors and systems often categorize them under text/x-sh or similar types to apply correct color coding and formatting rules automatically.

General FAQ

What is a MIME type?

A MIME (Multipurpose Internet Mail Extensions) type is a standard that indicates the nature and format of a document, file, or assortment of bytes. MIME types are defined and standardized in IETF's RFC 6838.

MIME types are important because they help browsers and servers understand how to process a file. When a browser receives a file from a server, it uses the MIME type to determine how to display or handle the content, whether it's an image to display, a PDF to open in a viewer, or a video to play.

MIME types consist of a type and a subtype, separated by a slash (e.g., text/html, image/jpeg, application/pdf). Some MIME types also include optional parameters.

How do I find the MIME type for a file?

You can check the file extension or use a file identification tool such as file --mime-type on the command line. Many programming languages also provide libraries to detect MIME types.

Why are multiple MIME types listed for one extension?

Different applications and historical conventions may use alternative MIME identifiers for the same kind of file. Showing them all helps ensure compatibility across systems.