I need to write a command that returns only a version number of a package, something like:
docker --version
Docker version 1.10.3, build 20f81dd
But that returns only the 1.10.3 part.
I need this for an Ansible playbook. Trying to parse the --version
works only if the package is installed, but when it isn't it throws errors. I'm hesitant to interprete the error as an absence of the package, an can't find anything that suits my needs.
I've tried several commands:
dpkg -l 'docker' | grep 'Version'
apt-cache policy docker | grep Installed
Both do their work, but Ansible gets huge amounts of excess data (as in every package file and their info, and that's no good if there are a lot of machines sending all that data around)
Is this even possible? Or should I look for a work-around?
Many thanks!
答案 0 :(得分:0)
This works for me :
➜ ~ dpkg -l |grep docker | awk 'NR==1{ print $3 }'| tr "~" "\n" | grep -v trusty
1.9.1-0