Skip to main content
4 of 6
deleted 144 characters in body

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

Final edit - the first answer works, I am using the function.

Sorry, I got confused myself 😅