I try to test if some packages are installed in my script before run it. To do that by the dpkg command. This is my code :
dpkg -s dialog
dialogStatut=$?
if [ "$dialogStatut" -eq 1 ]; then
//Install package
fi
I would like to make dpkg in silent mode (without echo). I have tried to put >&- 2>&- behind the command but if i do that the value is always 2 (if dialog is installed or not).
I have don't find solution in man dpkg. What is the best way to do that?
You are looking for 2> /dev/null
if ! dpkg -s dialog 2> /dev/null; then
...
fi
Consider just exiting your script to let dialog
be installed explicitly rather than making your script responsible for doing so.