From 3dccb74ec32e9c054ff3ab5c702702d1397b977f Mon Sep 17 00:00:00 2001 From: logicopslab Date: Wed, 29 Dec 2021 14:41:18 -0500 Subject: [PATCH] Status and Return Code --- 05.StatusAndCode/01.ExitStatus.sh | 4 ++++ 05.StatusAndCode/02.CheckingHost.sh | 11 +++++++++++ 05.StatusAndCode/03.ReturnCode.sh | 14 ++++++++++++++ 05.StatusAndCode/04.RC_Wait.sh | 12 ++++++++++++ 05.StatusAndCode/05.RC_With_Operators.sh | 15 +++++++++++++++ 5 files changed, 56 insertions(+) create mode 100644 05.StatusAndCode/01.ExitStatus.sh create mode 100644 05.StatusAndCode/02.CheckingHost.sh create mode 100644 05.StatusAndCode/03.ReturnCode.sh create mode 100644 05.StatusAndCode/04.RC_Wait.sh create mode 100644 05.StatusAndCode/05.RC_With_Operators.sh diff --git a/05.StatusAndCode/01.ExitStatus.sh b/05.StatusAndCode/01.ExitStatus.sh new file mode 100644 index 0000000..566946e --- /dev/null +++ b/05.StatusAndCode/01.ExitStatus.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +ls /no/such/folder +echo "$?" \ No newline at end of file diff --git a/05.StatusAndCode/02.CheckingHost.sh b/05.StatusAndCode/02.CheckingHost.sh new file mode 100644 index 0000000..9d9331a --- /dev/null +++ b/05.StatusAndCode/02.CheckingHost.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +HOST="www.google.com" +ping -c 2 $HOST + +if [ "$?" -eq "0" ] +then + echo "The Host $HOST is reachable." +else + echo "The Host $HOST is NOT reachable." +fi \ No newline at end of file diff --git a/05.StatusAndCode/03.ReturnCode.sh b/05.StatusAndCode/03.ReturnCode.sh new file mode 100644 index 0000000..9600c52 --- /dev/null +++ b/05.StatusAndCode/03.ReturnCode.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +HOST="www.google.com" +ping -c 2 $HOST + +RETURN_CODE=$? + +# Here RETURN_CODE contains the +# exit status + +if [ "$RETURN_CODE" != "0" ] +then + echo "The Host $HOST is NOT reachable." +fi \ No newline at end of file diff --git a/05.StatusAndCode/04.RC_Wait.sh b/05.StatusAndCode/04.RC_Wait.sh new file mode 100644 index 0000000..8ed4b26 --- /dev/null +++ b/05.StatusAndCode/04.RC_Wait.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +ping -c 1 -w 2 google.com +echo $? + +ping -c 1 -w 2 anything.microsoft.com +echo $? + +# man ping +# N +# /code +# q \ No newline at end of file diff --git a/05.StatusAndCode/05.RC_With_Operators.sh b/05.StatusAndCode/05.RC_With_Operators.sh new file mode 100644 index 0000000..45e0928 --- /dev/null +++ b/05.StatusAndCode/05.RC_With_Operators.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +# Using && + +mkdir LogicOpsLab && cp -v 04.RC_Wait.sh LogicOpsLab/04.RC_Wait.sh + +# -v is for verbose +# cp is copy + +echo $? + +# Using || + +cp -v 04.RC_Wait.sh LogicOpsLab/01.ExitStatus.sh || cp -v 04.RC_Wait.sh LogicOpsLabs/ExitStatus.sh +echo $? \ No newline at end of file