mirror of https://github.com/01-edu/public.git
3 changed files with 79 additions and 0 deletions
@ -0,0 +1,28 @@ |
|||||||
|
#!/usr/bin/env bash |
||||||
|
|
||||||
|
# Unofficial Bash Strict Mode |
||||||
|
set -euo pipefail |
||||||
|
IFS=' |
||||||
|
' |
||||||
|
|
||||||
|
FILENAME="student/burial.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/burial.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,2 @@ |
|||||||
|
sleep 2 & |
||||||
|
jobs -l | awk '{print $1, $3, $4, $5, $6}' |
@ -0,0 +1,49 @@ |
|||||||
|
## burial |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
Create a script `burial.sh` which will execute the job `sleep 2` in the background and then prints the list of running jobs using this command `jobs -l | awk '{print $1, $3, $4, $5, $6}'`. |
||||||
|
|
||||||
|
Expected output: |
||||||
|
|
||||||
|
```console |
||||||
|
$ ./burial.sh |
||||||
|
[1]+ Running sleep 2 & |
||||||
|
$ |
||||||
|
``` |
||||||
|
|
||||||
|
### Hints |
||||||
|
|
||||||
|
To run a job in the foreground and then send it to the background, you can use the `fg and bg` commands. |
||||||
|
|
||||||
|
The `fg` command allows you to bring a background job to the foreground, so that it becomes the active job in your terminal. The `bg` command allows you to continue running the job in the background. |
||||||
|
|
||||||
|
The `&` symbol is used in job control to run a command in the background as well. |
||||||
|
|
||||||
|
To run a command in the background, simply append an & at the end of the command. For example: |
||||||
|
|
||||||
|
`command &` |
||||||
|
|
||||||
|
This will run the command in the background, allowing you to continue using the terminal while the command is running. |
||||||
|
|
||||||
|
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 & |
||||||
|
$ fg %2 |
||||||
|
sleep 100 & |
||||||
|
^Z |
||||||
|
[2]+ Stopped sleep 100 |
||||||
|
$ bg %2 |
||||||
|
[2]+ sleep 100 & |
||||||
|
$ |
||||||
|
``` |
||||||
|
|
||||||
|
This will bring the second background job to the foreground. You can use the job number or the job's command line arguments to specify which job to bring to the foreground or send to the background. |
||||||
|
|
||||||
|
Once a job is in the foreground, you can use the "Ctrl + Z" keyboard shortcut to suspend it and send it to the background, or you can use the "Ctrl + C" to finish/close the job. |
||||||
|
|
||||||
|
> 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