0
I am using bash and I am trying to print a message to standard error if a variable is not set with the following command:
echo ${var:?"This var is not set"}
Now, I want to redirect that error message to a file. I tried the following but it didn't work:
echo ${var:?"This var is not set"} > testfile
Nor the following worked:
echo ${var:?"This var is not set"} 2> testfile
So, how can I direct this generated message to a file?