From f93a74941fc2923870613faeb52e1c12bcabe74a Mon Sep 17 00:00:00 2001 From: Rinsvent Date: Mon, 15 Aug 2022 22:52:18 +0700 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D1=85=D1=8D=D0=BB=D0=BF=D0=B5=D1=80=D1=8B=20=D0=B4=D0=BB=D1=8F?= =?UTF-8?q?=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B8=20=D0=BD?= =?UTF-8?q?=D0=B0=D0=BB=D0=B8=D1=87=D0=B8=D1=8F=20=D1=84=D0=B0=D0=B9=D0=BB?= =?UTF-8?q?=D0=B0=20=D0=B8=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA?= =?UTF-8?q?=D0=B8=20=D0=B4=D0=B0=D1=82=D1=8B=20=D0=BC=D0=BE=D0=B4=D0=B8?= =?UTF-8?q?=D1=84=D0=B8=D0=BA=D0=B0=D1=86=D0=B8=D0=B8=20=D0=B4=D0=B0=D1=82?= =?UTF-8?q?=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/io.sh | 22 ++++++++++++++++++---- src/io.test.sh | 19 ++++++++++++++++--- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/io.sh b/src/io.sh index e37e945..2eeb760 100644 --- a/src/io.sh +++ b/src/io.sh @@ -2,8 +2,22 @@ filePutContent() { local FILE_PATH=$1 - DIRECTORY_PATH=$(dirname $FILE_PATH) - mkdir -p $DIRECTORY_PATH - touch $FILE_PATH - echo $2 >> $FILE_PATH + DIRECTORY_PATH=$(dirname "$FILE_PATH") + mkdir -p "$DIRECTORY_PATH" + touch "$FILE_PATH" + echo "$2" >> "$FILE_PATH" } + +fileExists() { + if [ -f "$1" ]; + then + echo "1" + fi +} + +fileModifiedOlder() { + if [ "$(find "$1" -type f -mtime "$2")" ]; + then + echo "1" + fi +} \ No newline at end of file diff --git a/src/io.test.sh b/src/io.test.sh index 025aa63..667a94d 100644 --- a/src/io.test.sh +++ b/src/io.test.sh @@ -2,8 +2,21 @@ . ./io.sh -filePutContent ./temp.txt "Content was added successfuly1" -filePutContent ./temp.txt "Content was added successfuly2" +filePutContent ./temp.txt "Content was added successfully1" + +[ "$(fileExists ./temp.txt)" ] && echo "File exists" + +filePutContent ./temp.txt "Content was added successfully2" cat ./temp.txt -unlink ./temp.txt \ No newline at end of file +unlink ./temp.txt + +[ ! "$(fileExists ./temp.txt)" ] && echo "File not exists" + +today="$(date +%Y-%m-%d)" +nextDate=$(date +%Y-%m-%d -d "$today - 3 days") + +touch -mad "$nextDate 00:00:01" ./temp +[ "$(fileModifiedOlder ./temp 3)" ] && echo "File is older 3 days" +[ ! "$(fileModifiedOlder ./temp 4)" ] && echo "File is not older 4 days" +unlink ./temp \ No newline at end of file