From da685d8b85eb607e0320bad4f67333d0ed1e10ac Mon Sep 17 00:00:00 2001 From: miguel Date: Fri, 13 Jan 2023 15:10:44 +0000 Subject: [PATCH] fix(in-back-ground): fixing the test ang improving subject --- sh/tests/facts | 23 -------------------- sh/tests/in-back-ground_test.sh | 27 +++++++----------------- sh/tests/solutions/in-back-ground.sh | 2 +- subjects/devops/in-back-ground/README.md | 19 ++++++++++------- 4 files changed, 20 insertions(+), 51 deletions(-) delete mode 100644 sh/tests/facts diff --git a/sh/tests/facts b/sh/tests/facts deleted file mode 100644 index 9a3ffee5..00000000 --- a/sh/tests/facts +++ /dev/null @@ -1,23 +0,0 @@ -10 random facts - -- Avocados are a fruit, not a vegetable. They're technically considered a single-seeded berry, believe it or not. - -- The Eiffel Tower can be 15 cm taller during the summer, due to thermal expansion meaning the iron heats up, the particles gain kinetic energy and take up more space. - -- Trypophobia is the fear of closely-packed holes. Or more specifically, "an aversion to the sight of irregular patterns or clusters of small holes or bumps." No crumpets for them, then. - -- Australia is wider than the moon. The moon sits at 3400km in diameter, while Australia’s diameter from east to west is almost 4000km. - - EOF - -- 'Mellifluous' is a sound that is pleasingly smooth and musical to hear. - -- The Spice Girls were originally a band called Touch. "When we first started [with the name Touch], we were pretty bland," Mel C told The Guardian in 2018. "We felt like we had to fit into a mould." - -- Human teeth are the only part of the body that cannot heal themselves. Teeth are coated in enamel which is not a living tissue. - -- It's illegal to own just one guinea pig in Switzerland. It's considered animal abuse because they're social beings and get lonely. - -- The Ancient Romans used to drop a piece of toast into their wine for good health - hence why we 'raise a toast'. - -- The heart of a shrimp is located in its head. They also have an open circulatory system, which means they have no arteries and their organs float directly in blood. diff --git a/sh/tests/in-back-ground_test.sh b/sh/tests/in-back-ground_test.sh index 21b93720..4f3cbf7f 100755 --- a/sh/tests/in-back-ground_test.sh +++ b/sh/tests/in-back-ground_test.sh @@ -7,31 +7,20 @@ IFS=' FILENAME="student/in-back-ground.sh" script_dirS=$(cd -P "$(dirname "$BASH_SOURCE")" &>/dev/null && pwd) +echo "- Australia is wider than the moon. The moon sits at 3400km in diameter, while Australia's diameter from east to west is almost 4000km." >facts challenge() { submitted=$(cd "$1" && bash "$script_dirS"/$FILENAME) expected=$(cd "$1" && bash "$script_dirS"/solutions/in-back-ground.sh) diff <(echo "$submitted") <(echo "$expected") - if [ -s ${sol-output.log && output.log} ]; then - diff sol-output.log output.log - fi } -# True if FILE exists and is a regular file -if [ -f ${FILENAME} ]; then - # FILE exists and it's not empty - if [ -s ${FILENAME} ]; then - challenge . +challenge . - # This will faill the grep command - sed -i 's/moon/sun/g' facts - challenge . - sed -i 's/sun/moon/g' facts - else - echo "The file exist but is empty" - exit 1 - fi -else - echo "File does not exist" - exit 1 +echo "The sun is a star!" >facts +challenge . + +if [ -f sol-output ] && [ -f output ]; then + diff sol-output output + rm sol-output output fi diff --git a/sh/tests/solutions/in-back-ground.sh b/sh/tests/solutions/in-back-ground.sh index a90dc523..df8c1c5a 100755 --- a/sh/tests/solutions/in-back-ground.sh +++ b/sh/tests/solutions/in-back-ground.sh @@ -1 +1 @@ -nohup cat facts | grep "moon" && echo "The moon fact was found!" >sol-output.log 2>&1 & +nohup cat facts | grep "moon" && echo "The moon fact was found!" >sol-output & diff --git a/subjects/devops/in-back-ground/README.md b/subjects/devops/in-back-ground/README.md index 111115ba..9d13b204 100644 --- a/subjects/devops/in-back-ground/README.md +++ b/subjects/devops/in-back-ground/README.md @@ -6,10 +6,9 @@ Create a script `in-back-ground.sh` which will execute a job in the background t - Run the command `cat` on the file "facts" which will read the contents of the file and print it to `stdout`. - The output of the cat command will be piped to the `grep` command, which will search for the string `"moon"` in the file. -- If the `grep` command succeeds ( if it finds the string "moon"), the echo command will run and print `"The moon fact was found!"` to the `output.log` file. +- If the `grep` command succeeds (if it finds the string "moon"), the echo command will run and print `"The moon fact was found!"` to the `output` file. - If the command finds the string "moon", it will print the matching line to the `stdout`. -- Redirect the `stdout` to a new file `output.log`. -- Redirect `stderr` to the same place as `stdout` (in this case, the output.log file). +- Redirect the `stdout` to a new file `output`. You must do all these steps running only one job and using the command `nohup`! @@ -18,11 +17,17 @@ Expected output: ```console $ ./in-back-ground.sh nohup: redirecting stderr to stdout -- Australia is wider than the moon. The moon sits at 3400km in diameter, while Australia’s diameter from east to west is almost 4000km. +- Australia is wider than the moon. The moon sits at 3400km in diameter, while Australia's diameter from east to west is almost 4000km. $ ls -facts in-back-ground.sh output.log -$ cat output.log +facts in-back-ground.sh output +$ cat output The moon fact was found! +./in-back-ground.sh +nohup: redirecting stderr to stdout +$ ls +facts in-back-ground.sh +$ cat output +cat: output: No such file or directory $ ``` @@ -46,7 +51,5 @@ In a Unix-like shell, stdin, stdout, and stderr are three standard streams that - `stderr` (standard error) is a stream of data that a program or process writes to for error messages and other diagnostic output. It can also be redirected to write to a file or to the input of another command using the `2>` operator. -- You can use `2>&1` to redirect the `stderr` to the `stdout` current location. - > You have to use Man or Google to know more about commands flags, in order to solve this exercise! > Google and Man will be your friends!