diff --git a/sh/tests/count-files_test.sh b/sh/tests/count-files_test.sh new file mode 100755 index 00000000..122cba71 --- /dev/null +++ b/sh/tests/count-files_test.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +# Unofficial Bash Strict Mode +set -euo pipefail +IFS=' +' + +script_dirS=$(cd -P "$(dirname "$BASH_SOURCE")" &>/dev/null && pwd) + +challenge() { + submitted=$(cd "$1" && bash "$script_dirS"/student/count-files.sh) + expected=$(cd "$1" && bash "$script_dirS"/solutions/count-files.sh) + + diff <(echo "$submitted") <(echo "$expected") +} + +challenge cl-camp5/folder1 +challenge cl-camp5/folder2 diff --git a/sh/tests/solutions/count-files.sh b/sh/tests/solutions/count-files.sh new file mode 100755 index 00000000..1db83525 --- /dev/null +++ b/sh/tests/solutions/count-files.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +find . -type d,f | wc -l diff --git a/subjects/count-files/README.md b/subjects/count-files/README.md new file mode 100644 index 00000000..8ba82c6c --- /dev/null +++ b/subjects/count-files/README.md @@ -0,0 +1,22 @@ +## Count files + +### Instructions + +Create a file `count-files.sh`, which will print the number **(and only the number)** of regular files and folders contained in the current directory and its sub-folders (the current directory must be included in the count): + +### Usage + +```console +$ ./count-files.sh | cat -e +12$ +$ +``` + +**Tips:** + +Here are some Commands that can help you: + +- `find`. Find files or directories under the given directory tree, recursively. [For more information](https://manned.org/find). +- `wc`. Count lines, words, and bytes. [For more information](https://www.gnu.org/software/coreutils/wc). + +Use the man to get more info on the commands `find` and `wc`.