Browse Source

feat(lamp-in-the-dark): add subject, test and solution for the exercise

pull/1695/head
miguel 1 year ago
parent
commit
6e24f37261
  1. 28
      sh/tests/lamp-in-the-dark_test.sh
  2. 6
      sh/tests/solutions/lamp-in-the-dark.sh
  3. 39
      subjects/devops/lamp-in-the-dark/README.md

28
sh/tests/lamp-in-the-dark_test.sh

@ -0,0 +1,28 @@
#!/usr/bin/env bash
# Unofficial Bash Strict Mode
set -euo pipefail
IFS='
'
FILENAME="student/lamp-in-the-dark.sh"
# True if FILE exists and is a regular file
if [ -f ${FILENAME} ]; then
# FILE exists and it's not empty
if [ -s ${FILENAME} ]; then
if [[ $(cat $FILENAME | grep echo | wc -l) -ne 0 ]]; then
echo "echo is not allowed in this exercise!"
exit 1
fi
submitted=$(bash $FILENAME)
expected=$(bash solutions/lamp-in-the-dark.sh)
diff <(echo "$submitted") <(echo "$expected")
else
echo "The file exist but is empty"
exit 1
fi
else
echo "File does not exist"
exit 1
fi

6
sh/tests/solutions/lamp-in-the-dark.sh

@ -0,0 +1,6 @@
#!/bin/bash
sleep 4 &
sleep 3 &
sleep 2 &
jobs

39
subjects/devops/lamp-in-the-dark/README.md

@ -0,0 +1,39 @@
## lamp-in-the-dark
### Instructions
Create a script `lamp-in-the-dark.sh` which will list all background jobs that are currently running in your shell.
Add the following to your script:
```console
sleep 4 &
sleep 3 &
sleep 2 &
```
Expected output:
```console
# The processes running here are just an example
$ ./lamp-in-the-dark.sh
[1] Running sleep 4 &
[2]- Running sleep 3 &
[3]+ Running sleep 2 &
$
```
### Hints
You can use the `jobs` command to list all background jobs that are currently running in your shell. This will show you a list of all background jobs, along with their job numbers and status.
```console
$ jobs
[1]+ Running ping google.com &
[2]- Running sleep 100 &
```
- The flag `-l` show status and process IDs of all jobs.
> 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