Skip to main content
2 of 6
Editing this because I think people misunderstood the question, I am trying to get the version inside a shell script. Most of the given commands will work for a terminal but will have to be modified to work inside a shell script.

How do I get the version of a command inside a bash script

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 -

funny output

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 :/

Ah I think people misunderstood my question, I know you can get the version of a command one way or another, but this works only in the interactive terminal. I want to get the version inside a bash script.