So as the question suggests, I want to get the version of a command inside a bash script, instead of using the terminal.
I know that all available commands are present as files inside the directory /usr/bin. But it does not give the versions and it gives some funny information when you use cat for one of the (command) files.
for example - cat /usr/bin/man
gives -
What is this and how do I get the version?
I am using Ubuntu 20.04.
I know its a stupid question to ask here but I wasn't able to find anything :/
Supposedly the final edit - the accepted answer works for me, I am using the function.
I did also realise later that something like foo --version
will work too
But, if you are using a variable to store the version then you need to be careful about the syntax, I was doing it the wrong way. Thanks to @Romeo Ninov for pointing out that
foo --version
works too.
I am really sorry for these silly mistakes.