As the title says. You would use the "-n" flag to read the value of a variable and assign it to a shell variable
xy=$(fw_printenv -n xz)
But in the case that the U-Boot environment is empty and the value is fetched from default environment. The output is:
Environment WRONG, copy 0
Cannot read environment, using default
<value of xy>
where i only wanted the part.
While the second line goes to stdout and can be filtered by "2>/dev/null" the first one goes to stdout and breaks my script.
So my suggestion is to print debug and non-critical messages to stderr by default or handle the "-n" flag as quiet flag that suppresses such these messages.
I know that one of these messages can be disabled, when compiling with a defined NDEBUG, but this is not always doable and doesn't resolve the basic problem.