I'm running a Python script from within a Bash script and have been trying to assign that command's stderr
into a Bash variable. I think the issue is with how I'm referencing the variable, but am having trouble trying to identify what that problem is...
Here's what I'm doing and what I've tried:
#errorMessage=""
python test.py 2> $errorMessage
echo $errorMessage
Results in error code: test.sh: line 4: $errorMessage: ambiguous redirect
And with errorMessage actually declared, I get the same error message:
errorMessage=""
python test.py 2> $errorMessage
echo $errorMessage
The python file test.py
is set to write to stderr. I'm ultimately trying to check if this variable errorMessage
is empty or not to do more error handling; is checking the length of errorMessage
fine?