From b1762c3aac57d484e0c471595ce3a447c0e65051 Mon Sep 17 00:00:00 2001 From: Zouhair AMAZZAL Date: Sat, 3 Dec 2022 00:45:38 +0100 Subject: [PATCH] feat(json-researcher): add subject, test and solution for new a exercise --- sh/tests/json-researcher_test.sh | 16 +++++++ sh/tests/solutions/json-researcher.sh | 1 + subjects/json-researcher/README.md | 60 +++++++++++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 sh/tests/json-researcher_test.sh create mode 100755 sh/tests/solutions/json-researcher.sh create mode 100644 subjects/json-researcher/README.md diff --git a/sh/tests/json-researcher_test.sh b/sh/tests/json-researcher_test.sh new file mode 100644 index 00000000..c83d8094 --- /dev/null +++ b/sh/tests/json-researcher_test.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +# Unofficial Bash Strict Mode +set -euo pipefail +IFS=' +' + +echo insecure >> ~/.curlrc +caddy start &>/dev/null + +submitted=$(bash student/json-researcher.sh) +expected=$(bash solutions/json-researcher.sh) + +caddy stop &>/dev/null + +diff <(echo "$submitted") <(echo "$expected") diff --git a/sh/tests/solutions/json-researcher.sh b/sh/tests/solutions/json-researcher.sh new file mode 100755 index 00000000..6a66f96e --- /dev/null +++ b/sh/tests/solutions/json-researcher.sh @@ -0,0 +1 @@ +curl -s https://content.01-edu.org/assets/superhero/all.json | jq '.[] | select(.id==1)' | grep "name\|\"power\"" \ No newline at end of file diff --git a/subjects/json-researcher/README.md b/subjects/json-researcher/README.md new file mode 100644 index 00000000..a609799f --- /dev/null +++ b/subjects/json-researcher/README.md @@ -0,0 +1,60 @@ +## json-researcher + +### Instructions + +Create the script `json-researcher.sh` wich will show the "name" and the "power" of the superhero with `id: 1` + +- Where to look : https://((DOMAIN))/assets/superhero/all.json + +- What to use : `curl` and `jq` and `grep` + +- The output should be exactly like the example bellow but with the expected name + +```console +$./json-researcher.sh | cat -e + "name": "<...>",$ + "power": <...>,$ +$ +``` + +### Hints + +With `curl` you can get the content of the file from the url: +```console +$curl https://assets.01-edu.org/devops-branch/HeadTail.txt +<...> +$ +``` + +`jq` is a command-line utility that can slice, filter, and transform the components of a JSON file + +```console +$cat fruit.json +{ + "name": "apple", + "color": "green", + "price": 1.0 +} +$jq '.color' fruit.json +"green" +$ +``` + +`grep` is a command-line utility for searching plain-text data sets for lines that match a regular expression. + +```console +$cat fruit.json +{ + "name": "apple", + "color": "green", + "price": 1.0 +} +$cat fruit.json | grep color + "color": "green", +$ +``` + +May you will need to use `pipe (|)` and `&&`. + +> You have to use Man or Google to know more about commands flags, in order to solve this exercice! +> Google and Man will be your friends! \ No newline at end of file