mirror of https://github.com/01-edu/public.git
miguel
1 year ago
3 changed files with 73 additions and 0 deletions
@ -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 |
@ -0,0 +1,6 @@
|
||||
#!/bin/bash |
||||
|
||||
sleep 4 & |
||||
sleep 3 & |
||||
sleep 2 & |
||||
jobs |
@ -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…
Reference in new issue