feat(count-files): add subject, test and solution for the exercise count-files

This commit is contained in:
miguel 2022-11-30 17:34:07 +00:00 committed by MSilva95
parent 18a21bfe6d
commit 7849dc44fb
3 changed files with 43 additions and 0 deletions

18
sh/tests/count-files_test.sh Executable file
View File

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

View File

@ -0,0 +1,3 @@
#!/usr/bin/env bash
find . -type d,f | wc -l

View File

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