diff --git a/sh/tests/master-the-ls_test.sh b/sh/tests/master-the-ls_test.sh new file mode 100755 index 00000000..a4db521a --- /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 00000000..3180c356 --- /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 00000000..f5830f25 --- /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.