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