Bash
Goal
Write a Bash block that validates its input and publishes JSON safely. Time: 10 minutes. Needs: bash and jq on PATH.
Things to know
- Workflow Bash is always Bash, even if your terminal tab runs zsh or fish. On Windows, install Git Bash or expose WSL’s
bashonPATH. set -euo pipefailtogether withjq -emakes parse and validation errors fail the block.- Build output with
jq -n --argor--argjson. Never build JSON withecho "{\"message\":\"$x\"}", because quotes or newlines in$xwill break it. .shfiles, and files with unrecognised extensions, default to Bash in Code file.- ✦ Autogenerate writes Bash that reads each value with
jq.
Check your run
Execute step with the starter sample prints {"message":"Hello from curl"}. Step input {"trigger":{"text":42}} fails with trigger.text must be a string.
Exercise
Publish words (number): the number of whitespace-separated words in trigger.text.