From 9d2d50f9032d77ba31074e6f0e2c67afdfec38ea Mon Sep 17 00:00:00 2001 From: marcel-dempers Date: Mon, 13 Jan 2025 07:31:49 +1100 Subject: [PATCH] bash module updates --- .../operating-systems/scripting/bash/README.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/course/content/operating-systems/scripting/bash/README.md b/course/content/operating-systems/scripting/bash/README.md index b62cac7..9b9db18 100644 --- a/course/content/operating-systems/scripting/bash/README.md +++ b/course/content/operating-systems/scripting/bash/README.md @@ -225,7 +225,7 @@ This destination folder may be where our web server could be serving the files f # settings GITHUB_REPO_URL="https://github.com/marcel-dempers/my-website.git" DEPLOYMENT_SOURCE_DIR="$HOME/gitrepos/my-website" -DEPLOYMENT_DEST_DIR="/webites/my-website" +DEPLOYMENT_DEST_DIR="$HOME/webites/my-website" ``` Printing logs our output is very useful in scripting.
@@ -269,7 +269,7 @@ fi if [ expression ]; then # commands go here -elif +elif [ expression ]; then # other commands else # last commands @@ -470,6 +470,18 @@ echo "deployed website to $NEW_DEPLOYMENT_DIR" ### Error \ Exit code checking +We learned in our Command line module that all the commands we run are executable programs and most of them in Linux are kept under the `/bin` directory.
+ +When we run a command in Linux that run executable will return what we call an "Exit Code".
+In software engineering, programs will return a non-zero exit code when they terminate with an error.
+This means if a command in our script fails to run, it returns an exit code that is greater than 0 and our script will continue to execute.
+ +This may cause the outcome of our script executions to be undesirable.
+ +To overcome this we can always check the exit codes of commands using a special variable called `$?` which will contain the exit code of the previously executed program.
+ +Let's implement this for our two `git` commands that we have in our script and evaluate its exit status incase `git` fails: + ``` if [ $? -ne 0 ] then