检查是否设置了以某些前缀命名的任何变量?

Check if any variables, named with some prefix, are set?

我想要一个条件跳转,根据是否有定义的FOO_开头的变量。

我能做到:

SET FOO_ && (echo FOO is set) || (echo FOO not set)

这有效,但我得到了我不想要的额外输出:

Environment variable FOO_  not defined     <--- unwanted
FOO not set

如何抑制这个额外的输出?

我明白了。我必须将输出重定向到 nul

(SET FOO_ ) >nul 2>&1 && (echo FOO is set) || (echo FOO not set)

Here is some relevant documentation on redirection.