Skip to content

Instantly share code, notes, and snippets.

@ailtonbsj
Last active July 4, 2019 14:52
Show Gist options
  • Save ailtonbsj/6a489e9db3f88b3d6dcb5597c70a2d25 to your computer and use it in GitHub Desktop.
Save ailtonbsj/6a489e9db3f88b3d6dcb5597c70a2d25 to your computer and use it in GitHub Desktop.
A trick about expressions in bash without use of if
#!/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