v0.2.4

Documentation version

v0.2.4v0.3.2
en

Documentation language

en

Search documentation

ESC

Documentation search

What are you working on?

Find a guide, configuration option, action, or ESH topic.

Browse documentation
DocsData, files, and HTTP

Data, files, and HTTP

Automation often moves information between project files and services. ESH includes common tools in its runtime, so scripts can focus on the work without checking which host utilities are installed.

Read project data

json and yaml read an inline document or a file. The -g (--get) option follows a dot path and writes the value to standard output, so you can use it in command substitution.

PACKAGE='{"name":"everyinit","version":"1.2.3","downloads":{"bytes":2048}}'
NAME="$(json -g name "$PACKAGE")"
VERSION="$(json -g version "$PACKAGE")"
BYTES="$(json -g downloads.bytes "$PACKAGE")"

echo "$NAME $VERSION ships $BYTES bytes"

Validate input before continuing when a missing or malformed document should stop the workflow:

json -v package.json || exit 1
yaml -v config.yaml || exit 1

Work with files explicitly

Wildcard characters are literal in ESH. Use glob to expand path patterns and path to inspect a path instead of guessing from its spelling.

mkdir -p ./dist

for FILE in $(glob "./assets/*.svg"); do
  cp "$FILE" ./dist
done

path --exists ./dist || exit 1
archive ./dist/release.zip ./dist
sha256sum ./dist/release.zip > ./dist/release.zip.sha256

The Runtime Reference lists filesystem, archive, hash, and text commands with their options and exit statuses.

Call a service without curl

http makes an in-process HTTP request. It succeeds for a 2xx response and returns a non-zero status for network or HTTP errors. Handle that status with the same control flow you use for other commands.

wait_port 127.0.0.1:8080 15s || exit 1

retry -n 3 -d 1s http GET http://127.0.0.1:8080/health || {
  echo "Service did not become healthy" >&2
  exit 1
}

Next: learn control flow and failure handling before combining these commands into larger scripts.

Page source: book/esh/20.work-with-project-data.md