From 9dbebae75666266345c4375261b9f5aceaa0248d Mon Sep 17 00:00:00 2001 From: miguel Date: Wed, 30 Nov 2022 17:49:27 +0000 Subject: [PATCH] feat(master-the-ls): add subject, test and solution for the exercise master-the-ls --- sh/tests/master-the-ls_test.sh | 18 ++++++++++++++++++ sh/tests/solutions/master-the-ls | 3 +++ subjects/master-the-ls/README.md | 23 +++++++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100755 sh/tests/master-the-ls_test.sh create mode 100755 sh/tests/solutions/master-the-ls create mode 100644 subjects/master-the-ls/README.md diff --git a/sh/tests/master-the-ls_test.sh b/sh/tests/master-the-ls_test.sh new file mode 100755 index 000000000..a4db521a8 --- /dev/null +++ b/sh/tests/master-the-ls_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/master-the-ls) + expected=$(cd "$1" && bash "$script_dirS"/solutions/master-the-ls) + + diff <(echo "$submitted") <(echo "$expected") +} + +challenge cl-camp1/folder1 +challenge cl-camp1/folder2 diff --git a/sh/tests/solutions/master-the-ls b/sh/tests/solutions/master-the-ls new file mode 100755 index 000000000..3180c3564 --- /dev/null +++ b/sh/tests/solutions/master-the-ls @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +ls -p -tu | tr '\n' ',' | sed 's/.$//' diff --git a/subjects/master-the-ls/README.md b/subjects/master-the-ls/README.md new file mode 100644 index 000000000..f5830f25f --- /dev/null +++ b/subjects/master-the-ls/README.md @@ -0,0 +1,23 @@ +## Master the ls + +### Instructions + +Put in a file `master-the-ls`, the command line that will: + +- list the files and directories of the current directory. +- Ignore the hidden files, the "." and the "..". +- Separates the results with commas. +- Order them by ascending order of access time (the newest first). +- Have the directories ends with a `/`. + +### Hint + +Here are some Commands that can help you: + +- `tr`. Translate characters: run replacements based on single characters and character sets.For more information: https://www.gnu.org/software/coreutils/tr. + + - Replace all occurrences of a character in a file, and print the result: + `tr {{find_character}} {{replace_character}} < {{filename}}` + +- `ls`. List directory contents. For more information: https://www.gnu.org/software/coreutils/ls. +- `sed`. Edit text in a scriptable manner. You can see also: awk. For more information: https://www.gnu.org/software/sed/manual/sed.html.