FG
💻 Software

How do I return a failure value from a bash function?

Fresh7 days ago
Mar 15, 202632660 views
Confidence Score0%
0%

Problem

Background In this posting, the following solution was posted: will invoke a command, if has in its name. However, I normally invoke this command like: Question How do I modify the code above so that it returns a value on failure such that the second part, does not get invoked? Probably returning s…

Error Output

function cmakerel {
    if expr match "$PWD" '*bld*' >/dev/null ; then
        cmake -D....
    else
        echo "Wrong directory!"
    fi
}

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix for: How do I return a failure value from a bash function?

Low Risk

Add below the call to exit the function with the same exit code as , and add below the call to exit with , which is non-zero and therefore indicates an error. You can alternatively (if you call both commands in combination) add the call to this func…

Awaiting Verification

Be the first to verify this fix

Sign in to verify this fix

Environment