Skip to main content

Shebang Support

Runme badget

Shebang is a versatile tool designed to execute scripts written in various scripting languages including Shell, Perl, Python, and more. Runme integrates Shebang to enable users to run the script of their choice directly from the Markdown file in their preferred programming language.

Prerequisites

Before proceeding with the integration of Shebang in Runme, ensure that Runme is properly installed on your system. This is a crucial step to guarantee the smooth execution of your runbooks

Run your Code with Runme in VS Code Using Shebang

Runme gives you the power to run your code right inside your Markdown file in VS Code without having to switch to a terminal. To do this, follow the steps below:

  1. Click on the +Code icon.
  2. Enter the script you would like to run.
  3. Click on the Select Cell Language Mode and select a language of your choice.
  4. Now click on Execute Cell

Configuring Shebang Custom Interpreter in VS Code

Before proceeding with the integration of Shebang in Runme, ensure that Runme is properly installed on your system. This is a crucial step to guarantee the smooth execution of your runbooks

Alternatively, if you would love to run your code using your specified interpreter version, you can achieve that using the custom interpreter feature. This allows you to configure the environment for running code directly within your editor, making your coding experience much smoother and easier.

shebang-language-mood

Follow the steps below to set up the Shebang custom interpreter in VS Code:

  1. Open your script (Markdown file) in VS Code
  2. Click on Configure menu at the buttom right of your code block
  3. Click on Advance
  4. Set the path to the system interpreter of your choice.

shebang-interpreter

  1. Close the modular
  2. Execute the Runme command:
# short for "runme tui" is
runme

shebang-output

Examples of Shebang Lines for Different Languages

We have attached some scripts in various languages as seen below to enable you to test how Runme works in your VS Code.

Each of the following examples, written in Python, Ruby, Bash, and Node.js (JavaScript), accomplishes the same task: they define a greeting ("Hello, World!"), obtain the current date and time, and then combine these into a single message. The primary difference lies in the syntax and functions/methods used for date and time formatting in each language.

Python

To run the Python code, you need to set the path to the Python interpreter, which is /usr/bin/python3, in the advanced section of your configuration in your code block.

import datetime

# Define a variable for the greeting
greeting = "Hello, World!"

# Get the current date and time
currentDateTime = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')

# Concatenate the greeting with the current date and time
fullGreeting = greeting + " It's now " + currentDateTime

# Output the full greeting
print(fullGreeting)

Bash

To use Bash, you need to set the Interpreter to point to the Bash interpreter, which is /usr/bin/bash, in the advanced section of your configuration in your code block.


# Define a variable for the greeting
greeting="Hello, World!"

# Get the current date and time
currentDateTime=$(date '+%Y-%m-%d %H:%M:%S')

# Concatenate the greeting with the current date and time
fullGreeting="$greeting It's now $currentDateTime"

# Output the full greeting
echo $fullGreeting

Ruby

To use Ruby, you need to add the path to the Ruby interpreter, which is /usr/bin/ruby, in the advanced section of your configuration in your code block.

# Define a variable for the greeting
greeting = "Hello, World!"

# Get the current date and time
currentDateTime = Time.now.strftime("%Y-%m-%d %H:%M:%S")

# Concatenate the greeting with the current date and time
fullGreeting = "#{greeting} It's now #{currentDateTime}"

# Output the full greeting
puts fullGreeting

PHP

To use PHP, you need to add the path to the PHP interpreter, which is /usr/bin/php, in the advanced section of your configuration in your code block..

<?php
// PHP Script Example: Greeting with Date and Time

// Define a variable for the greeting
$greeting = "Hello, World!";

// Get the current date and time
$currentDateTime = date('Y-m-d H:i:s');

// Concatenate the greeting with the current date and time
$fullGreeting = $greeting . " It's now " . $currentDateTime;

// Output the full greeting
echo $fullGreeting;
?>

Node

To use Node.js, you need to add the path to the node interpreter, which is /usr/bin/node, in the advanced section of your configuration in your code block.

// Define a variable for the greeting
const greeting = "Hello, World!";

// Get the current date and time
const currentDateTime = new Date().toISOString().replace('T', ' ').substring(0, 19);

// Concatenate the greeting with the current date and time
const fullGreeting = `${greeting} It's now ${currentDateTime}`;

// Output the full greeting
console.log(fullGreeting);

List of Auto-Detected Language Runtimes

Runme auto-detects runtimes based on the language selection per cell.

NameLanguageIDsRuntime (first match wins)
Bash Shellbashbash
Windows cmd.execmdcmd
Windows cmd.exedoscmd
Fish Shellfishfish
Javascriptjavascript, js, jsx, javascriptreactnode
Korn Shellkshksh
Lualualua
Perlperlperl
PHPphpphp
PowerShellpowershellpowershell
Pythonpython, pypython3, python
Rubyruby, rbruby
Unix Shellshell, shbash, sh
Typescripttypescript, ts, tsx, typescriptreactts-node, deno, bun
Z Shellzshzsh

Missing a language? Please raise an issue.

Combining Multiple Languages in Your Notebook

It's possible to combine multiple languages in a single notebook by using different shebang lines for each script block. For an example of a notebook with multiple languages, see the Shebang Notebooks example on GitHub.