Bash if

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

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