From c8511651ff748a72b32e4c327f9d4ba14de723c9 Mon Sep 17 00:00:00 2001 From: eslopfer Date: Thu, 5 Jan 2023 15:36:08 +0000 Subject: [PATCH] docs(file-checker): add description of subject --- subjects/devops/file-checker/README.md | 54 ++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 subjects/devops/file-checker/README.md diff --git a/subjects/devops/file-checker/README.md b/subjects/devops/file-checker/README.md new file mode 100644 index 000000000..a4f69e1f1 --- /dev/null +++ b/subjects/devops/file-checker/README.md @@ -0,0 +1,54 @@ +## file-checker + +### Instructions + +In this exercise you will make a script `file-checker.sh` that will check the status of a given file using if statements. + +Your script should make the following checks: + +- File exists. + +- File is readable. + +- File is writable. + +- File is executable. + +It should output the status as in the example in the usage. + +You should also handle what to do when no file is provided. The use of `test` command is not allowed for this exercise. + +### Usage + +```console +$ ./file-checker.sh file.txt +File exists +File is readable +File is not writable +File is not executable +$ ./file-checker.sh +Error: No file provided +$ +``` + +### Hints + +[bash conditional expressions](https://www.gnu.org/software/bash/manual/html_node/Bash-Conditional-Expressions.html) can be used to solve this exercise. + +For example for `script.sh`: + +```bash +#!/usr/bin/env bash + +if [ -s $1] ; then + echo "File size greater than 0" +fi +``` + +And its output: + +```console +$ ./script.sh file.txt +File size greater than 0 +$ +```