No matter what I seem to do, I can't seem to get the output of a command to be assigned to a variable in bash. Although my script runs find without any errors, I'm not getting the result I want:
# Prompt if the user needs Qt
echo ""
echo "Checking for qt5-default."
echo ""
OUTPUT="$(sudo dpkg -s qt5-default)"
echo "OUTPUT:"
echo $OUTPUT
...
OUTPUT will never echo anything. However, if I do:
OUTPUT="$(ls -la)"
Then it works. I'm wondering why.
Here is what I mean:

As you can see, the "OUTPUT:" string comes after the command output, which means that the output wasn't stored in the variable, but was run in the main shell, which confuses me.
Here is what happens when OUTPUT="$(ls -la)":

In this case, "OUTPUT:" comes before, showing that the echo command worked correctly.
Any ideas?
2>&1at the end of the command.