Browse Source

feat(largest): add new bash exercise

- add subject, solution, test and support files
pull/1796/head
nprimo 2 years ago committed by eslopfer
parent
commit
06dc3ff388
  1. 1
      sh/tests/largest-dir/.abc
  2. 1
      sh/tests/largest-dir/folder1/.hello
  3. 1
      sh/tests/largest-dir/folder1/ab
  4. 1
      sh/tests/largest-dir/folder1/ac
  5. 1
      sh/tests/largest-dir/folder1/az
  6. 1
      sh/tests/largest-dir/folder1/bz
  7. 1
      sh/tests/largest-dir/folder1/cz
  8. 1
      sh/tests/largest-dir/folder1/za!
  9. 1
      sh/tests/largest-dir/folder2/aa/.salut
  10. 1
      sh/tests/largest-dir/folder2/aa/aa
  11. 1
      sh/tests/largest-dir/folder2/aa/az
  12. 0
      sh/tests/largest-dir/folder2/aa/ba/ab
  13. 0
      sh/tests/largest-dir/folder2/aa/ba/bz
  14. 1
      sh/tests/largest-dir/folder2/ab
  15. 0
      sh/tests/largest-dir/folder2/ac
  16. 0
      sh/tests/largest-dir/folder2/alphabet
  17. 0
      sh/tests/largest-dir/folder2/az
  18. 1
      sh/tests/largest-dir/folder2/ba/.ola
  19. 1
      sh/tests/largest-dir/folder2/ba/aa/.ciao
  20. 0
      sh/tests/largest-dir/folder2/ba/aa/alphabetz!
  21. 0
      sh/tests/largest-dir/folder2/ba/aa/cz
  22. 0
      sh/tests/largest-dir/folder2/ba/aa/za!
  23. 0
      sh/tests/largest-dir/folder2/ba/ac
  24. 0
      sh/tests/largest-dir/folder2/ba/alphabetz
  25. 1
      sh/tests/largest-dir/folder2/bz
  26. 0
      sh/tests/largest-dir/folder2/cz
  27. 1
      sh/tests/largest-dir/folder2/za!
  28. 24
      sh/tests/largest_test.sh
  29. 3
      sh/tests/solutions/largest.sh
  30. 46
      subjects/devops/largest/README.md

1
sh/tests/largest-dir/.abc

@ -0,0 +1 @@
ciao mamma guarda come mi diverto

1
sh/tests/largest-dir/folder1/.hello

@ -0,0 +1 @@
ciao mamma guarda qu

1
sh/tests/largest-dir/folder1/ab

@ -0,0 +1 @@
123

1
sh/tests/largest-dir/folder1/ac

@ -0,0 +1 @@
1

1
sh/tests/largest-dir/folder1/az

@ -0,0 +1 @@
12

1
sh/tests/largest-dir/folder1/bz

@ -0,0 +1 @@
12

1
sh/tests/largest-dir/folder1/cz

@ -0,0 +1 @@
12345678

1
sh/tests/largest-dir/folder1/za!

@ -0,0 +1 @@
12

1
sh/tests/largest-dir/folder2/aa/.salut

@ -0,0 +1 @@
123456

1
sh/tests/largest-dir/folder2/aa/aa

@ -0,0 +1 @@
12

1
sh/tests/largest-dir/folder2/aa/az

@ -0,0 +1 @@
123

0
sh/tests/largest-dir/folder2/aa/ba/ab

0
sh/tests/largest-dir/folder2/aa/ba/bz

1
sh/tests/largest-dir/folder2/ab

@ -0,0 +1 @@
123456

0
sh/tests/largest-dir/folder2/alphabet

1
sh/tests/largest-dir/folder2/ba/.ola

@ -0,0 +1 @@
1234512312312312

1
sh/tests/largest-dir/folder2/ba/aa/.ciao

@ -0,0 +1 @@
123456

0
sh/tests/largest-dir/folder2/ba/aa/alphabetz!

0
sh/tests/largest-dir/folder2/ba/aa/cz

0
sh/tests/largest-dir/folder2/ba/aa/za!

0
sh/tests/largest-dir/folder2/ba/alphabetz

1
sh/tests/largest-dir/folder2/bz

@ -0,0 +1 @@
123

1
sh/tests/largest-dir/folder2/za!

@ -0,0 +1 @@
12312312312 12 312 312 12 3

24
sh/tests/largest_test.sh

@ -0,0 +1,24 @@
#!/usr/bin/env bash
set -euo pipefail
IFS='
'
FILENAME="student/largest.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/largest.sh)
diff <(echo "$submitted") <(echo "$expected")
}
if [ $(cat "$script_dirS"/"$FILENAME" | grep echo) ]; then
echo "echo is not allowed in this exercise!"
exit 1
fi
challenge largest-dir/folder1
challenge largest-dir/folder2
challenge largest-dir

3
sh/tests/solutions/largest.sh

@ -0,0 +1,3 @@
#!/usr/bin/env bash
find . -type f -exec ls -lha {} \; | sort -hrk5 | head -7 | awk '{printf("%5s | ", $5); print $NF}'

46
subjects/devops/largest/README.md

@ -0,0 +1,46 @@
## largest
### Instructions
Crate a script `largest.sh` that will look for, and display on the console, the seven biggest files in the current directory (including subdirectories) in a specific format.
The script will also have to find and take into account hidden files.
### Usage
Here is an example of how to use the script:
```console
$ tree -ha
[4.0K] .
├── [4.0K] d1
   ├── [4.0K] d1-1
   ├── [ 2] f1-1
   ├── [ 27] f1-2
   ├── [ 24] f1-3
   ├── [ 24] f1-4
   ├── [ 3] f2-1
   ├── [ 34] f2-2
   ├── [ 38] f2-3
   └── [ 87] .hf1-1
├── [ 5] f1
├── [ 18] f2
└── [ 34] f3
2 directories, 11 files
$ bash largest.sh | cat -e
87 | ./d1/.hf1-1$
5 | ./f1$
3 | ./d1/f2-1$
38 | ./d1/f2-3$
34 | ./d1/f2-2$
34 | ./f3$
2 | ./d1/f1-1$
$
```
> The output needs to be formatted as the example shown above
### Hints
- `awk` might be handy
Loading…
Cancel
Save