You should easily deal with awk or something, but here's how I do it:
echo $GCC_PREPROCESSOR_DEFINITIONS | grep -Po 'SANDBOX_ENV=\d+' | sed 's/SANDBOX_ENV=//'
In the context of your echo:
echo "SANDBOX value is $(echo $GCC_PREPROCESSOR_DEFINITIONS | grep -Po 'SANDBOX_ENV=\d+' | sed 's/SANDBOX_ENV=//')"
I basically passed the contents of GCC_PREPROCESSOR_DEFINITIONS and cut out the SANDBOX_ENV part.
grep -P
- use Perl regex \ d + because I don't like POSIX. Just a preference. In fact, that
grep -P 'SANDBOX_ENV=\d+'
it is to find the line in the content passed to it, which contains the line "SANDBOX_ENV =" and any number of digits following it. If the value can contain alphanumeric characters, you can change \ d for digits to \ w for a word that covers a-zA-Z0-9, and you get:
grep -Po 'SANDBOX_ENV=\w+'
The + symbol simply means that there must be at least one character of the type specified by the character, including all subsequent characters that match.
-o (match only) in grep -Po is used to highlight a match, so instead of the entire line, you just get "SANDBOX_ENV = 1".
This output is then passed to the sed command, where I do a simple search and replace, where I replaced "SANDBOX_ENV =" with "", leaving only the value behind it. There are probably simpler ways to do this, as with awk, but you must find out for yourself.