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