A first test-run shell script, and curl with jq for an API check
Write a small script that runs your tests and reports the result, then check an API from the terminal with curl and jq.
L1–L4 are part of the Pro pass
L0 Explain simply
Analogy: a shop opening checklist. The owner follows a paper list, in order. If one job fails, such as no power, the owner stops and does not open. At the end, one note says open or not open. A phone call can also ask a supplier if a delivery is ready.
The list is a shell script. Each command is a job. The is the note. The phone call is against the app.
Tom, a tester at Daily List, a to-do list app, writes the list so the same run happens every time. Mei, the test lead, wants one number that says pass or fail.
What it is: A is a text file of terminal commands. The shebang is the first line, #!/bin/bash, and it names the program that runs the file. An go together. An exit code is the number a command leaves behind. Zero means success. Any other number means a problem. set -e tells the shell to stop when a command fails, with a few exceptions. A curl and jq API check calls a web address and picks one field from the reply. An API is an application programming interface. The reply here is JSON, which is JavaScript Object Notation. Typing the same commands by hand is the nearest neighbour, and it is easy to skip a step.
Why it matters: A hand-typed run invites skips and typos. A script that hides a failure can tell a job that Daily List passed. Continuous integration, or CI, is a system that runs the tests for you. Tom needs a script whose exit code tells the truth.
PLAIN WORDS · 1 in this section
- typos
- Small spelling or typing mistakes in text.
PICTURE IT
The picture is the one the lesson above opens with. The table below shows how each part of it matches the software.
THE REAL JOB A shop opening checklist.
- List
- Stop rule
- Note
HOW THE PICTURE MAPS
| In the picture | In the software |
|---|---|
| A paper list of jobs in order | A shell script |
| The line that says who follows the list | The shebang |
| Stopping when one job fails | The line set -e |
| The note open or not open | The exit code |
| A phone call to the supplier | The curl command |
WHERE THIS PICTURE STOPS
- A paper list can be read by anyone, but a script needs permission to run.
- A shop note says why, but an exit code is only a number.
- A supplier answers in words, but a reply needs jq to pick one field.
HOOK
A checklist, a stop rule and a note.
TELL A FRIEND
A checklist, a stop rule and a note.
OFTEN MIXED UP WITH Linux pipes and redirection: save a test log and filter it. That topic saves and filters output with pipes and output signs. This one packs the commands into a script and checks an .
Sources & standards — 9 sources
- Market practice
GNU Bash Reference Manual ↗ — GNU · Bash 5.2 publisher tagged source — Selected Pipelines, Redirections, Environment, Shell Scripts, special parameters, errexit, pipefail, ENV/BASH_ENV and kill.
Selected publisher sections read for Testing Tools audit. Bash 5.2 publisher tagged source. This is not live service testing or a full-publication certification.
- Market practice
GNU file permissions: symbolic modes ↗ — GNU · Coreutils 9.7 included permissions chapter — Symbolic Modes/Setting Permissions/Umask: u owner, + add, x execute; omitted user is affected by umask. Use chmod u+x for this example.
Selected publisher sections read for Testing Tools audit. Coreutils 9.7 included permissions chapter. This is not live service testing or a full-publication certification.
- Market practice
curl --fail option ↗ — curl project · 8.14.1 — Full option: HTTP >=400 normally exits22 and suppresses response body; authentication caveats include401/407.
Selected publisher sections read for Testing Tools audit. 8.14.1. This is not live service testing or a full-publication certification.
- Market practice
curl --fail-with-body option ↗ — curl project · 8.14.1 — Full option: HTTP failure retains body, introduced7.76.0. Selected silent/show-error option files also read for -sS.
Selected publisher sections read for Testing Tools audit. 8.14.1. This is not live service testing or a full-publication certification.
- Market practice
jq 1.8 manual ↗ — jq project · 1.8 manual; publisher jq-1.8.1 source compared — Invoking jq: input streams, shell quoting, -r and -e statuses0/1/4; -e tests last result against false/null, not strict boolean true.
Selected publisher sections read for Testing Tools audit. 1.8 manual; publisher jq-1.8.1 source compared. This is not live service testing or a full-publication certification.
- Market practice
pytest exit codes ↗ — pytest project · Current stable read 7 November 2026, compared8.4.0 source — Actual current stable operative exit-code page includes0–6. Older8.4.0 tagged page has0–5; code6 too-many-warnings is version-scoped.
Selected publisher sections read for Testing Tools audit. Current stable read 7 November 2026, compared8.4.0 source. This is not live service testing or a full-publication certification.
- Market practice
npm scripts ↗ — npm · Version11 route, accessed7 November2026; npm-test11.21.2 route marked Legacy — Selected shell execution and nonzero script-aborts-process guidance; npm-test Description confirms configured scripts.test and ignore-scripts exceptions.
Selected publisher sections read for Testing Tools audit. Version11 route, accessed7 November2026; npm-test11.21.2 route marked Legacy. This is not live service testing or a full-publication certification.
- Market practice
curl --silent option ↗ — curl project · curl 8.14.1 — Full option: suppress progress meter and curl error messages, but do not suppress requested response data.
Full publisher option file read for the Testing Tools analysis before implementation. curl 8.14.1; no live external service tested.
- Market practice
curl --show-error option ↗ — curl project · curl 8.14.1 — Full option: when used with --silent, show curl error messages on failure.
Full publisher option file read for the Testing Tools analysis before implementation. curl 8.14.1; no live external service tested.
PRACTISE AND KEEP
Sources for this topic — 9 sources
- Market practice
GNU Bash Reference Manual ↗ — GNU · Bash 5.2 publisher tagged source — Selected Pipelines, Redirections, Environment, Shell Scripts, special parameters, errexit, pipefail, ENV/BASH_ENV and kill.
Selected publisher sections read for Testing Tools audit. Bash 5.2 publisher tagged source. This is not live service testing or a full-publication certification.
- Market practice
GNU file permissions: symbolic modes ↗ — GNU · Coreutils 9.7 included permissions chapter — Symbolic Modes/Setting Permissions/Umask: u owner, + add, x execute; omitted user is affected by umask. Use chmod u+x for this example.
Selected publisher sections read for Testing Tools audit. Coreutils 9.7 included permissions chapter. This is not live service testing or a full-publication certification.
- Market practice
curl --fail option ↗ — curl project · 8.14.1 — Full option: HTTP >=400 normally exits22 and suppresses response body; authentication caveats include401/407.
Selected publisher sections read for Testing Tools audit. 8.14.1. This is not live service testing or a full-publication certification.
- Market practice
curl --fail-with-body option ↗ — curl project · 8.14.1 — Full option: HTTP failure retains body, introduced7.76.0. Selected silent/show-error option files also read for -sS.
Selected publisher sections read for Testing Tools audit. 8.14.1. This is not live service testing or a full-publication certification.
- Market practice
jq 1.8 manual ↗ — jq project · 1.8 manual; publisher jq-1.8.1 source compared — Invoking jq: input streams, shell quoting, -r and -e statuses0/1/4; -e tests last result against false/null, not strict boolean true.
Selected publisher sections read for Testing Tools audit. 1.8 manual; publisher jq-1.8.1 source compared. This is not live service testing or a full-publication certification.
- Market practice
pytest exit codes ↗ — pytest project · Current stable read 7 November 2026, compared8.4.0 source — Actual current stable operative exit-code page includes0–6. Older8.4.0 tagged page has0–5; code6 too-many-warnings is version-scoped.
Selected publisher sections read for Testing Tools audit. Current stable read 7 November 2026, compared8.4.0 source. This is not live service testing or a full-publication certification.
- Market practice
npm scripts ↗ — npm · Version11 route, accessed7 November2026; npm-test11.21.2 route marked Legacy — Selected shell execution and nonzero script-aborts-process guidance; npm-test Description confirms configured scripts.test and ignore-scripts exceptions.
Selected publisher sections read for Testing Tools audit. Version11 route, accessed7 November2026; npm-test11.21.2 route marked Legacy. This is not live service testing or a full-publication certification.
- Market practice
curl --silent option ↗ — curl project · curl 8.14.1 — Full option: suppress progress meter and curl error messages, but do not suppress requested response data.
Full publisher option file read for the Testing Tools analysis before implementation. curl 8.14.1; no live external service tested.
- Market practice
curl --show-error option ↗ — curl project · curl 8.14.1 — Full option: when used with --silent, show curl error messages on failure.
Full publisher option file read for the Testing Tools analysis before implementation. curl 8.14.1; no live external service tested.
Deepest material on this page: L4 — Standards & sources. Where a topic stops short of implementation depth, that is a deliberate coverage decision, not an oversight — see coverage.