Print the one function's log to the screen

c()
{
     if something failed;then
    echo "failed"
    exit 1 
     fi
}

f()
{
functinona  #if something failed call "c"
functionb   #if something failed call "c"  
}

f > log 2>&1 #put the log to file not print on the screen

I want all the stdout/stdrr to the log file without print on the screen, but I want the function "c" 's output on the screen

Redirect the echo to the tty:

echo "failed" > /dev/tty

But this will work only if there is an active tty. But if you add:

if tty -s; then
   exec 3> /dev/tty # corrected from /dev/null
else
  exec 3>&2
fi

at the top of your script, and then change the echo to:

echo "failed" 1>&3

This will send the failed messages to stderr if there is no tty.

f()
{
    echo "xx"
        if tty -s; then
           exec 3> /dev/null
        else
          exec 3>&2
        fi
        echo "failed" 1>&3
}

f > x


I don't see the "failed" print on the screen
-------------------------------------------------------------------------------------

but if I use below, it works

f()
{
    echo "xx"
        if tty -s; then
           exec 3> /dev/null
        else
          exec 3>&2
        fi
        echo "failed" > /dev/tty
}

f > x  2>&1


Apologies, it should have been:

exec 3> /dev/tty