From 6ce50f2bde9b701799b98be7f6e00476ba172637 Mon Sep 17 00:00:00 2001 From: miguel Date: Fri, 30 Dec 2022 12:41:19 +0000 Subject: [PATCH] feat(burial): add subject, test and solution for the exercise --- sh/tests/burial_test.sh | 28 ++++++++++++++++++ sh/tests/solutions/burial.sh | 2 ++ subjects/devops/burial/README.md | 49 ++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100755 sh/tests/burial_test.sh create mode 100755 sh/tests/solutions/burial.sh create mode 100644 subjects/devops/burial/README.md diff --git a/sh/tests/burial_test.sh b/sh/tests/burial_test.sh new file mode 100755 index 000000000..dcab8b912 --- /dev/null +++ b/sh/tests/burial_test.sh @@ -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 diff --git a/sh/tests/solutions/burial.sh b/sh/tests/solutions/burial.sh new file mode 100755 index 000000000..f7e31a9ce --- /dev/null +++ b/sh/tests/solutions/burial.sh @@ -0,0 +1,2 @@ +sleep 2 & +jobs -l | awk '{print $1, $3, $4, $5, $6}' diff --git a/subjects/devops/burial/README.md b/subjects/devops/burial/README.md new file mode 100644 index 000000000..5d187ad92 --- /dev/null +++ b/subjects/devops/burial/README.md @@ -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!