I am a beginner with bash so I apologize if this is a basic question or has syntax issues but I couldn't find the answer anywhere. I want to run a command, and if it fails, check if the error message matches a certain string. Here is what I have:
err_msg=`./command input.txt 2>&1`
if [$? -eq 1]
then
if [err_msg -eq "Error: timeout"]
then
#do something
fi
fi
Is this the correct way to do this? If I'm using the first line to define the error message err_msg, will $? still store the pass/fail status of the command? Also, what will happen to if the command passes? Will err_msg just be blank?