From 13435eb8f1f4b9d822ec12f733b4b63c0e912725 Mon Sep 17 00:00:00 2001 From: miguel Date: Thu, 22 Dec 2022 15:32:12 +0000 Subject: [PATCH] docs(set-env-vars): add hints, fixx the test to block echo and fix solution --- sh/tests/set-env-vars_test.sh | 11 ++++++++++- sh/tests/solutions/set-env-vars.sh | 3 +-- subjects/devops/set-env-vars/README.md | 22 +++++----------------- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/sh/tests/set-env-vars_test.sh b/sh/tests/set-env-vars_test.sh index c1dc6294d..e84ad193d 100755 --- a/sh/tests/set-env-vars_test.sh +++ b/sh/tests/set-env-vars_test.sh @@ -5,7 +5,16 @@ set -euo pipefail IFS=' ' -submitted=$(bash student/set-env-vars.sh) +FILENAME="student/set-env-vars.sh" + +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 +fi + +submitted=$(bash $FILENAME) expected=$(bash solutions/set-env-vars.sh) diff <(echo "$submitted") <(echo "$expected") diff --git a/sh/tests/solutions/set-env-vars.sh b/sh/tests/solutions/set-env-vars.sh index 712c43a78..12768eeca 100755 --- a/sh/tests/solutions/set-env-vars.sh +++ b/sh/tests/solutions/set-env-vars.sh @@ -3,5 +3,4 @@ export MY_MESSAGE="Hello World" export MY_NUM=100 export MY_PI=3.142 -export MY_ARR=(one, two, three, four, five) -printenv +printenv | grep "MY_" diff --git a/subjects/devops/set-env-vars/README.md b/subjects/devops/set-env-vars/README.md index 5b2869f21..7c9065a65 100644 --- a/subjects/devops/set-env-vars/README.md +++ b/subjects/devops/set-env-vars/README.md @@ -2,7 +2,7 @@ ### Instructions -Create a script `set-env-vars.sh`, which will allow you to set the following variables as environment variables and and print them all: +Create a script `set-env-vars.sh`, which will allow you to set the following variables as environment variables and and print only the ones you created: - `MY_MESSAGE` which contains the string `"Hello World"`. - `MY_NUM` which contains the number `100`. @@ -28,28 +28,14 @@ LESSCLOSE=/usr/bin/lesspipe %s %s _=/usr/bin/printenv $ ./set-env-vars.sh MY_NUM=100 -SHELL=/bin/bash -TERM=xterm -USER=demouser -LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca:... -MAIL=/var/mail/demouser -PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games -PWD=/home/demouser -LANG=en_US.UTF-8 MY_PI=3.142 -SHLVL=1 -HOME=/home/demouser -LOGNAME=demouser MY_MESSAGE=Hello World -LESSOPEN=| /usr/bin/lesspipe %s -LESSCLOSE=/usr/bin/lesspipe %s %s -_=/usr/bin/printenv $ ``` ### Hints -Setting values to environment variables +Setting values to environment variables: In order to set a value to an existing environment variable, we use an assignment expression. For instance, to set the value of the "LANG" variable to "he_IL.UTF-8", we use the following command: @@ -57,7 +43,7 @@ In order to set a value to an existing environment variable, we use an assignmen $ LANG=he_IL.UTF-8 ``` -If we use an assignment expression for a variable that doesn't exist, the shell will create a shell variable, which is similar to an environment variable but does not influence the behaviour of other applications. +If we use an assignment expression for a variable that doesn't exist, the shell will create a shell variable, which is similar to an environment variable but does not influence the behavior of other applications. A shell variable can be exported to become an environment variable with the export command. To create the "EDITOR" environment variable and assign the value "nano" to it, you can do: @@ -66,5 +52,7 @@ $ EDITOR=nano $export EDITOR ``` +`echo` is not allowed in the exercise! Try to use the command `printenv` and filter with `grep` to get only the variables that you created. + > 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!