How can I highlight the Bash/shell commands in Markdown files?

For example, to highlight js, I write:

function () { return "This code is highlighted as Javascript!"}

To highlight HTML code I use ```html.

How can we highlight Bash/shell commands?


If you are looking to highlight a shell session command sequence as it looks to the user (with prompts, not just as contents of a hypothetical script file), then the right identifier to use at the moment is console:

foo@bar:~$ whoami

GitHub Markdown preview tab screenshot

  • 27
    This is a more accurate answer. The highlighting includes the prompt, whereas bash, sh, zsh, and shell do not consider the start of the line to be the prompt and don't colour it properly. Thanks!
    – mikesigs
    Sep 26 '18 at 2:16
  • 1
    Nice! Is there a reference for this standard? Is it git flavored md or something else? Thanks! Apr 19 '19 at 0:30
  • 2
    @JorgeOrpinel I believe I dug it up in the list of languages supported by GitHub’s syntax highlighter here. Dec 1 '19 at 14:30
  • 3
    I see shell-session mentioned more than console
    – huyz
    Aug 23 '20 at 1:29

It depends on the Markdown rendering engine and the Markdown flavour. There is no standard for this. If you mean GitHub flavoured Markdown for example, shell should work fine. Aliases are sh, bash or zsh. You can find the list of available syntax lexers here.

  • 1
    I provided a bit more details on how to deduce language specifiers for Markdown from the linked file above here: stackoverflow.com/a/45786100/6884590, in case that's useful to anyone finding this question.
    – pchaigno
    Jan 8 '18 at 12:07
  • thanks this help me in this moment that I started a documentaion in MarkDown files.
    – LandiLeite
    Jul 20 '20 at 21:58

I found a good description at Markdown Cheatsheet:

Code blocks are part of the Markdown spec, but syntax highlighting isn't.

However, many renderers -- like GitHub's and Markdown Here -- support syntax highlighting. Which languages are supported and how those language names should be written will vary from renderer to renderer. Markdown Here supports highlighting for dozens of languages (and not-really-languages, like diffs and HTTP headers); to see the complete list, and how to write the language names, see the highlight.js demo page.

Although I could not find any official GitHub documentation about using highlight.js, I've tested lots of languages and seemed to be working

To see list of languages I used https://github.com/highlightjs/highlight.js/blob/master/SUPPORTED_LANGUAGES.md

Some shell samples:

Shell:      console, shell
Bash:       bash, sh, zsh
PowerShell: powershell, ps
DOS:        dos, bat, cmd


cd \
copy a b

If I need only to highlight the first word as a command, I often use properties:

npm run build

I obtain something like:

npm run build


Using the knitr package:

```{r, engine='bash', code_block_name} ...


```{r, engine='bash', count_lines}
wc -l en_US.twitter.txt

You can also use:

  • engine='sh' for shell
  • engine='python' for Python
  • engine='perl', engine='haskell' and a bunch of other C-like languages and even gawk, AWK, etc.
  • 3
    Does not do anything on a local .md file? Does it have to be a web served doc to work? Jan 16 '17 at 16:14

Per the documentation from GitHub regarding GFM syntax highlighted code blocks

We use Linguist to perform language detection and syntax highlighting. You can find out which keywords are valid in the languages YAML file.

Rendered on GitHub, console makes the lines after the console blue. bash, sh, or shell don't seem to "highlight" much ...and you can use posh for PowerShell or CMD.


Bitbucket uses CodeMirror for syntax highlighting. For Bash or shell you can use sh, bash, or zsh. More information can be found at Configuring syntax highlighting for file extensions and Code mirror language modes.

Your Answer

