From 5558a83c62b70209b9ed15d30d75c76939277968 Mon Sep 17 00:00:00 2001 From: eslopfer Date: Thu, 5 Jan 2023 16:54:24 +0000 Subject: [PATCH] feat(file-checker): add solution for exercise --- sh/tests/solutions/file-checker.sh | 38 ++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 sh/tests/solutions/file-checker.sh diff --git a/sh/tests/solutions/file-checker.sh b/sh/tests/solutions/file-checker.sh new file mode 100644 index 00000000..2b201246 --- /dev/null +++ b/sh/tests/solutions/file-checker.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +# Check if the script was given an argument +if [ $# -ne 1 ] +then + echo "Error: a file must be provided as an argument" + exit 1 +fi + +# Check if file exists +if [ ! -e "$1" ] +then + echo "File does not exist" +else + echo "File exists" +fi + +# Check file's permissions +if [ -r "$1" ] +then + echo "File is readable" +else + echo "File is not readable" +fi + +if [ -w "$1" ] +then + echo "File is writable" +else + echo "File is not writable" +fi + +if [ -x "$1" ] +then + echo "File is executable" +else + echo "File is not executable" +fi