diff --git a/sh/tests/set-internal-vars_test.sh b/sh/tests/set-internal-vars_test.sh new file mode 100755 index 000000000..215541462 --- /dev/null +++ b/sh/tests/set-internal-vars_test.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +# Unofficial Bash Strict Mode +set -euo pipefail +IFS=' +' + +submitted=$(bash student/set-internal-vars.sh) +expected=$(bash solutions/set-internal-vars.sh) + +diff <(echo "$submitted") <(echo "$expected") diff --git a/sh/tests/solutions/set-internal-vars.sh b/sh/tests/solutions/set-internal-vars.sh new file mode 100755 index 000000000..91312683f --- /dev/null +++ b/sh/tests/solutions/set-internal-vars.sh @@ -0,0 +1,8 @@ +MY_MESSAGE="Hello World" +MY_NUM=100 +MY_PI=3.142 +MY_ARR=(one, two, three, four, five) +echo $MY_MESSAGE +echo $MY_NUM +echo $MY_PI +echo ${MY_ARR[*]} diff --git a/subjects/devops/set-internal-vars/README.md b/subjects/devops/set-internal-vars/README.md new file mode 100644 index 000000000..34f91aec2 --- /dev/null +++ b/subjects/devops/set-internal-vars/README.md @@ -0,0 +1,32 @@ +## set-internal-vars + +### Instructions + +Create a script `set-internal-vars.sh`, which will allow you to create and print the following variables. + +- `MY_MESSAGE` which contains the string `"Hello World"`. +- `MY_NUM` which contains the number `100`. +- `MY_PI` which contains the number `3.142`. +- `MY_ARR` which contains `(one two three four five)` + +Expected output: + +```console +$ ./set-internal-vars.sh +Hello World +100 +3.142 +one, two, three, four, five +$ +``` + +### Hints + +Creating variables: + +Variables can be created either at the shell or in shell-scripts. Any variable created within a shell script is lost when the script stops executing. A variable created at the prompt, however, will remain in existence until the shell is terminated. The syntax for creating a variable is : + +`=` + +> 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!