Bash if

From NovaOrdis Knowledge Base
Revision as of 19:43, 20 February 2018 by Ovidiu (talk | contribs) (→‎Internal)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Internal

Overview


if <command-that-returns-0-or-non-0>; then
    #
    # execute this is the command returned 0
    #
else
    #
    # execute this is the command returned non-0
    #
fi

Example:

function my-test() {
    return 0
    #return 1
}

if my-test; then
    echo "my-test() returned 0"
else
    echo "my-test() returned non-0"
fi