Skip to content
Latchkey

How to Run a Multi-Line Inline Script in GitHub Actions

A YAML pipe block (run: |) lets one step contain many shell lines that share the same shell process.

Use the | block scalar after run: to write several commands. They all execute in one shell invocation, so variables set on one line are visible on the next.

Steps

  • Write run: | then indent the command lines beneath it.
  • Keep every line at the same indent so YAML preserves them.
  • Remember state persists across lines in a single step, but not across steps.

Workflow

.github/workflows/ci.yml
steps:
  - run: |
      echo "Preparing build"
      VERSION=$(cat VERSION)
      echo "Building version $VERSION"
      make build VERSION="$VERSION"

Gotchas

  • GitHub bash runs each step with set -eo pipefail, so a failing line aborts the step.
  • A variable set in one step is gone in the next; persist it via $GITHUB_ENV if later steps need it.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →