Skip to content

Instantly share code, notes, and snippets.

@tiagopog
Created January 31, 2018 12:40
Show Gist options
  • Save tiagopog/1eba457730f89a4b4371e0bb149332c1 to your computer and use it in GitHub Desktop.
Save tiagopog/1eba457730f89a4b4371e0bb149332c1 to your computer and use it in GitHub Desktop.
##
# Simple "if" statement
##
if [ "foo" == "foo" ]; then
echo "I'm in! (1)"
fi
# Short version
[ "foo" = "foo" ] && echo "I'm in! (2)"
# Test version
test "foo" = "foo" && echo "I'm in! (3)"
##
# "if/elif/else" statement
##
if [ "foo" != "foo" ]; then
echo "It won't enter here"
elif [ "foo" == "bar" ]; then
echo "It won't enter here"
else
echo "I'm in! (4)"
fi
##
# "case" statement
##
case "foobar" in
foo*)
echo "I'm in! (5)"
;;
bar)
echo "It won't match \"bar\""
;;
*)
echo "It would enter here if nothing matches"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment