From cbdc5c4a6f14e89e6512bfbf4626f3eb0343458a Mon Sep 17 00:00:00 2001 From: Zouhair AMAZZAL Date: Thu, 1 Dec 2022 23:25:47 +0100 Subject: [PATCH] feat(head-and-tail): add subject, test and solution for new a exercise --- sh/tests/head-and-tail_test.sh | 16 +++++++++ sh/tests/solutions/head-and-tail.sh | 1 + subjects/head-and-tail/README.md | 50 +++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 sh/tests/head-and-tail_test.sh create mode 100755 sh/tests/solutions/head-and-tail.sh create mode 100644 subjects/head-and-tail/README.md diff --git a/sh/tests/head-and-tail_test.sh b/sh/tests/head-and-tail_test.sh new file mode 100644 index 00000000..d0ee2ebe --- /dev/null +++ b/sh/tests/head-and-tail_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/head-and-tail.sh) +expected=$(bash solutions/head-and-tail.sh) + +caddy stop &>/dev/null + +diff <(echo "$submitted") <(echo "$expected") diff --git a/sh/tests/solutions/head-and-tail.sh b/sh/tests/solutions/head-and-tail.sh new file mode 100755 index 00000000..fdd1575f --- /dev/null +++ b/sh/tests/solutions/head-and-tail.sh @@ -0,0 +1 @@ +curl --silent https://assets.01-edu.org/devops-branch/HeadTail.txt | head -1 && curl --silent https://assets.01-edu.org/devops-branch/HeadTail.txt | tail -1 \ No newline at end of file diff --git a/subjects/head-and-tail/README.md b/subjects/head-and-tail/README.md new file mode 100644 index 00000000..c5a9d533 --- /dev/null +++ b/subjects/head-and-tail/README.md @@ -0,0 +1,50 @@ +## head-and-tail + +### Instructions + +Create the script `head-and-tail.sh` wich will show the first and last lines of the file `HeadTail.txt` + +- Where to look : https://assets.01-edu.org/devops-branch/HeadTail.txt + +- What to use : `curl` and `head` and `tail` + +- The output should be exactly like the example bellow but with the expected name + +```console +$./head-and-tail.sh | cat -e +Hello My username is: <...>,$ +so my passwd is: <...>$ +$ +``` + +### 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 +<...> +$ +``` + +`head` print the top N number of data of the given input. By default, it prints the first 10 lines of the specified files: + +```console +$head file + +$head -1 file + +$ +``` + +`tail` print the last N number of data of the given input. By default, it prints the last 10 lines of the specified files: + +```console +$tail file + +$tail -1 file + +$ +``` + +May you will need to use `pipe (|)` and "&&".