You can learn how to save standard error to a variable in Bash by reading the quick guide published by TecAdmin.
How to Store Standard Error to a Variable in Bash
In Bash, you can store the standard error output of a command to a variable by using the `2>&1` operator and the `$()` command substitution syntax. Here `2>` redirects the error message to &1`, that represent to standard output. In the case of bash shell works as the standard output device.
How to Store Standard Error to a Variable in Bash – TecAdmin