Browse Source

DEV-3916 feat(bin-status) add subject and tests for bin-status exercise

DEV-4191-DeepInSystem
Zouhair AMAZZAL 2 years ago committed by Michele
parent
commit
95509fae9a
  1. 34
      sh/tests/bin-status_test.sh
  2. 3
      sh/tests/solutions/bin-status.sh
  3. 33
      subjects/devops/bin-status/README.md

34
sh/tests/bin-status_test.sh

@ -0,0 +1,34 @@
#!/usr/bin/env bash
# Unofficial Bash Strict Mode
set -euo pipefail
IFS='
'
FILENAME="student/bin-status.sh"
challenge() {
submitted=$(eval "$1" ; bash $FILENAME)
expected=$(eval "$1" ; bash solutions/bin-status.sh)
diff <(echo "$submitted") <(echo "$expected")
}
# True if FILE exists and is a regular file
if [ -f ${FILENAME} ]; then
# FILE exists and it's not empty
if [ -s ${FILENAME} ]; then
challenge true
challenge false
challenge ls -l
challenge ls asdasdasdasdad
else
echo "The file exist but is empty"
exit 1
fi
else
echo "File does not exist"
exit 1
fi

3
sh/tests/solutions/bin-status.sh

@ -0,0 +1,3 @@
#!/usr/bin/env bash
echo $?

33
subjects/devops/bin-status/README.md

@ -0,0 +1,33 @@
## json-researcher
### Instructions
Create the script `bin-status.sh` that will return the exit status of last command
- What to use : `echo`
- The output should be exactly like the example bellow but with the expected name
```console
$ true ; ./bin-status.sh
0
$ false ; ./bin-status.sh
1
$
```
### Hints
`$?` is a variable that holds the return value of the last executed command.
`echo $?` displays 0 if the last command has been successfully executed and displays a non-zero value if some error has occurred.
The bash sets `$?` To the exit status of the last executed process. By convention 0 is a successful exit and non-zero indicates some kind of error. It can be used to check if the previous command has been executed without any errors. If it has executed successfully then it stores 0. `$?` is also useful in shell scripts as a way to decide what to do depending on how the last executed command worked by checking the exit status.
```console
$ random-binary ; echo $?
<...>
<the exit status of random-binary>
$
```
> You have to use Man or Google to know more about commands flags, in order to solve this exercise!
> Google and Man will be your friends!
Loading…
Cancel
Save