From 5245101b9143d84c2b960477eec8156c3818031b Mon Sep 17 00:00:00 2001 From: miguel Date: Tue, 27 Dec 2022 11:24:40 +0000 Subject: [PATCH] feat(right): add subject, test and solution for the exercise --- sh/tests/right/sample1.txt | 0 sh/tests/right/sample2 | 0 sh/tests/right/sample3.txt | 0 sh/tests/right/sample4 | 0 sh/tests/right_test.sh | 18 ++++++++++++++++++ sh/tests/solutions/right.sh | 1 + subjects/devops/right/README.md | 28 ++++++++++++++++++++++++++++ 7 files changed, 47 insertions(+) create mode 100644 sh/tests/right/sample1.txt create mode 100644 sh/tests/right/sample2 create mode 100644 sh/tests/right/sample3.txt create mode 100644 sh/tests/right/sample4 create mode 100755 sh/tests/right_test.sh create mode 100755 sh/tests/solutions/right.sh create mode 100644 subjects/devops/right/README.md diff --git a/sh/tests/right/sample1.txt b/sh/tests/right/sample1.txt new file mode 100644 index 000000000..e69de29bb diff --git a/sh/tests/right/sample2 b/sh/tests/right/sample2 new file mode 100644 index 000000000..e69de29bb diff --git a/sh/tests/right/sample3.txt b/sh/tests/right/sample3.txt new file mode 100644 index 000000000..e69de29bb diff --git a/sh/tests/right/sample4 b/sh/tests/right/sample4 new file mode 100644 index 000000000..e69de29bb diff --git a/sh/tests/right_test.sh b/sh/tests/right_test.sh new file mode 100755 index 000000000..1fb898e80 --- /dev/null +++ b/sh/tests/right_test.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +# Unofficial Bash Strict Mode +set -euo pipefail +IFS=' +' + +FILENAME="student/right.sh" +script_dirS=$(cd -P "$(dirname "$BASH_SOURCE")" &>/dev/null && pwd) + +challenge() { + submitted=$(cd "$1" && bash "$script_dirS"/$FILENAME) + expected=$(cd "$1" && bash "$script_dirS"/solutions/right.sh) + diff <(echo "$submitted") <(echo "$expected") + diff $1"/filtered_files_sol.txt" $1"/filtered_files.txt" +} + +challenge right diff --git a/sh/tests/solutions/right.sh b/sh/tests/solutions/right.sh new file mode 100755 index 000000000..6c799cf4c --- /dev/null +++ b/sh/tests/solutions/right.sh @@ -0,0 +1 @@ +ls | grep -v "\.txt" >filtered_files_sol.txt diff --git a/subjects/devops/right/README.md b/subjects/devops/right/README.md new file mode 100644 index 000000000..7ec295005 --- /dev/null +++ b/subjects/devops/right/README.md @@ -0,0 +1,28 @@ +## right + +### Instructions + +Create a file `right.sh` that will get the output of a file and parse it, and then write it to a file with a specific format using a single command. + +Get the output of the `ls` command, parse it with the `grep` command to filter for files without a `.txt` extension, and write the output to a file called `filtered_files.txt`, check the example bellow: + +### Usage + +```console +$ ls -l +sample1.txt sample2 sample3.txt sample4 +$ ./right.sh +$ cat filtered_files.txt +sample2 +sample4 +$ +``` + +### Hints + +command1 | command2 > output_file + +Here, command1 is the command that generates the output you want to parse, and command2 is the command that parses the output. The output of command2 will be redirected to the file output_file using the > operator. + +> 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!