Browse Source

feat(head-and-tail): add subject, test and solution for new a exercise

DEV-4017-prototypes-exercise-1-animals
Zouhair AMAZZAL 2 years ago committed by Zouhair AMAZZAL
parent
commit
cbdc5c4a6f
  1. 16
      sh/tests/head-and-tail_test.sh
  2. 1
      sh/tests/solutions/head-and-tail.sh
  3. 50
      subjects/head-and-tail/README.md

16
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")

1
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

50
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
<first 10 lines>
$head -1 file
<first 1 line>
$
```
`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
<last 10 lines>
$tail -1 file
<last 1 line>
$
```
May you will need to use `pipe (|)` and "&&".
Loading…
Cancel
Save