Last active
July 4, 2019 14:52
-
-
Save ailtonbsj/6a489e9db3f88b3d6dcb5597c70a2d25 to your computer and use it in GitHub Desktop.
A trick about expressions in bash without use of if
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function expressionsWithoutIf { | |
A=$1 | |
B=$2 | |
[ "$A" -ge "$B" ] ; C=$? | |
if [ "$C" == "0" ]; then | |
echo "TRUE!" | |
else | |
echo "FALSE!" | |
fi | |
C=$((A > B)) | |
if [ "$C" == "1" ]; then | |
echo "TRUE!" | |
else | |
echo "FALSE!" | |
fi | |
if [ "$A" -ge "$B" ]; then | |
echo "TRUE!" | |
else | |
echo "FALSE!" | |
fi | |
} | |
expressionsWithoutIf 70 40 | |
expressionsWithoutIf 70 90 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment