$ curl cheat.sh/
# If you look at the man file for `local` (which is actually just the
# BASH builtins man page), it is treated as its own command, which gives
# an exit code of `0` upon successfully creating the local variable. So
# `local` is overwriting the last-executed error code.
# 
# Try this:

 function testing { local test; test="$(return 1)"; echo $?; }; testing

# **EDIT:** I went ahead and tried it for you, and it works.
# 
# [Chriszuma] [so/q/9524623] [cc by-sa 3.0]

$
Follow @igor_chubin cheat.sh