Skip to content

Commit

Permalink
Status and Return Code
Browse files Browse the repository at this point in the history
  • Loading branch information
logicopslab committed Dec 29, 2021
1 parent 1f5f66b commit 3dccb74
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 0 deletions.
4 changes: 4 additions & 0 deletions 05.StatusAndCode/01.ExitStatus.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

ls /no/such/folder
echo "$?"
11 changes: 11 additions & 0 deletions 05.StatusAndCode/02.CheckingHost.sh
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions 05.StatusAndCode/03.ReturnCode.sh
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions 05.StatusAndCode/04.RC_Wait.sh
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions 05.StatusAndCode/05.RC_With_Operators.sh
Original file line number Diff line number Diff line change
@@ -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 $?

0 comments on commit 3dccb74

Please sign in to comment.