Skip to main content

Runme by Example

Discover the various ways you can use Runme to run your code straight from your markdown file. In this section, you will find variety of features and examples to help you get the most out of Runme..

Environment Variable Prompts

Set and use environment variables in your code. For example:

export SLEEP_SECS="5"
echo "Sleeping for $SLEEP_SECS seconds..."
sleep $SLEEP_SECS
echo "Awake now!"

There are two prompt modes: using 1.) a placeholder or 2.) a prompt message. Learn more about them at Environment Variable Prompts.

export PROJECT_ID=Enter a valid project ID
cli make-call --project-id $PROJECT_ID describe

Advanced Usage of Piping and Variables

Runme allows for complex piping and usage of variables across cells. Here is an example using Git:

  1. List Git Branches Matching a Pattern:
  git branch | grep "feature-"
  1. Process the Output in a Subsequent Cell:
echo "$__" | while read line
do
if [ ! -z "$line" ]; then echo "Feature branch: ${line}"; fi
done

Key Configuration Feature/Flags

Customize your file executing using Runme configuration feature

You can control (or customize) how your Markdown file is executed with the configurations feature (add link). This feature gives you the option to execute individual cells or the entire file based on your selected option.

Shebangs

Specify the interpreter path in your cell configuration setting :

print('Hello World!')

Working with Stdin, Stdout, and Stderr

  1. Reading from stdin and Writing to stdout:
 $ cat
Enter your text here.
^D

Use cat to read from stdin and write to stdout.

  1. Redirecting stdin and stdout:
  $ cat < input.txt > output.txt

Redirects stdin from input.txt and stdout to output.txt.

  1. Appending to an Existing File:
  $ echo "New content." >> existing_file.txt

Appends text to existing_file.txt.

  1. Redirecting stderr:
  $ ls non_existent_dir 2> error_log.txt

Redirects stderr to error_log.txt.

  1. Redirecting stderr to stdout:
$ ls non_existent_dir 2>&1

Redirects both stderr and stdout.

  1. Piping Output:
 $ ls | grep ".txt"

Pipes the output of ls to grep.

  1. Redirecting stdout and stderr to Different Files:
 $ myprogram > output.log 2> error.log

Separately redirects stdout and stderr.

Installation via Terminal

brew install runme

These examples showcase improved ways you can use Runme in your documentation to enhance your workflow and overall documentation process.

If you encounter any challenge with these practices, please don't hesitate to reach out us. We're here to help and would be glad to assist you.