Browse Source

fix(in-back-ground): fixing the test ang improving subject

DEV-4397-piscine-ai-missing-file-for-ex-7-of-nlp
miguel 1 year ago committed by MSilva95
parent
commit
da685d8b85
  1. 23
      sh/tests/facts
  2. 27
      sh/tests/in-back-ground_test.sh
  3. 2
      sh/tests/solutions/in-back-ground.sh
  4. 19
      subjects/devops/in-back-ground/README.md

23
sh/tests/facts

@ -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.

27
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

2
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 &

19
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 Australias 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!

Loading…
Cancel
Save