From 9bdb8f12177fd8d17c5bfc4ee4f1eecbc022d4af Mon Sep 17 00:00:00 2001 From: nprimo Date: Mon, 16 Jan 2023 16:49:24 +0100 Subject: [PATCH] feat(remake): clarify exercise - specify what happens when directory passed as argument does not exist - add hints in subjects - update solution and tests accordingly --- sh/tests/remake_test.sh | 11 +++++++---- sh/tests/solutions/remake.sh | 3 +-- subjects/devops/remake/README.md | 16 +++++++++++++++- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/sh/tests/remake_test.sh b/sh/tests/remake_test.sh index 6e8126bbe..6cc718276 100644 --- a/sh/tests/remake_test.sh +++ b/sh/tests/remake_test.sh @@ -4,16 +4,19 @@ IFS=' ' challenge () { - if [[ $# -eq 1 ]]; then + if [[ $# -eq 1 && -d "$1" ]]; then submitted=$(bash student/remake.sh "$1") expected=$(bash solutions/remake.sh "$1"-expected) diff <(echo $submitted) <(echo $expected) diff <(ls -ltr $1) <(ls -ltr $1-expected) - rm -rf "$1" "$1-expected" else diff <(bash student/remake.sh "$@") <(bash solutions/remake.sh "$@") fi } -challenge remake -challenge +mkdir remake remake-expected +challenge remake +challenge +challenge not-there +rm -rf remake remake-expected + diff --git a/sh/tests/solutions/remake.sh b/sh/tests/solutions/remake.sh index 4460b92de..bd6c64b32 100644 --- a/sh/tests/solutions/remake.sh +++ b/sh/tests/solutions/remake.sh @@ -3,8 +3,7 @@ IFS=' ' -if [[ $# -eq 1 ]]; then - mkdir -p $1 +if [[ $# -eq 1 && -d "$1" ]]; then cd $1 touch -t 01010001 ciao chmod 442 ciao diff --git a/subjects/devops/remake/README.md b/subjects/devops/remake/README.md index e2f76af52..b10280a02 100644 --- a/subjects/devops/remake/README.md +++ b/subjects/devops/remake/README.md @@ -4,7 +4,7 @@ Create a file `remake.sh`, which will take one argument, the relative path of a directory, and will create new files and directories in it. The new files and directories created must have the same name, permission and modification dates as shown in the example below. -If the number of given arguments is not one, your script should print `Error` and exit with the status code 1. +If the number of given arguments is not one or if the directory given as argument does not exist, your script should print `Error` and exit with the status code 1. Below the expected behavior of your script: @@ -25,5 +25,19 @@ $ - `touch -t ` allows to specify the modification time in the format `[[CC]YY]MMDDhhmm[.ss]` instead of the current time for the file at ``. +- it is possible to check whether a file or a directory exists with the following commands: + +```bash +if [[ -d $DIRPATH ]]; then # for a directory + echo "the $DIRPATH exists" +fi +``` + +```bash +if [[ -f $FILEPATH ]]; then # for a file + echo "the $FILEPATH exists" +fi +``` + > You have to use Man or Google to know more about commands flags, in order to solve this exercise! > Google and Man will be your friends!