Bash if: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=Internal= * bash =Overview=")
 
 
(4 intermediate revisions by the same user not shown)
Line 2: Line 2:


* [[bash#Built-In_Commands|bash]]
* [[bash#Built-In_Commands|bash]]
* [[Bash_Expressions#.5B.5B....5D.5D|[[...]]]]


=Overview=
=Overview=
<pre>
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
</pre>
Example:
<pre>
function my-test() {
    return 0
    #return 1
}
if my-test; then
    echo "my-test() returned 0"
else
    echo "my-test() returned non-0"
fi
</pre>

Latest revision as of 19:43, 20 February 2018

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