Skip to main content
added 355 characters in body
Source Link

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

FinalSupposedly the final edit - the accepted answer works for me, I am using the function.

SorryI 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 got confused myself 😅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.

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 accepted answer works for me, I am using the function.

Sorry, I got confused myself 😅

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

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.

Became Hot Network Question
added 10 characters in body
Source Link

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 firstaccepted answer works for me, I am using the function.

Sorry, I got confused myself 😅

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 😅

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 accepted answer works for me, I am using the function.

Sorry, I got confused myself 😅

deleted 144 characters in body
Source Link

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

EditFinal edit - Love the answers but I think people misunderstood my question. I know you can get the version of a command - one way or another, but thisfirst answer works only in, I am using the interactive terminalfunction.

I want to get the version inside a shell script instead.Sorry, I got confused myself 😅

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

Edit - Love the answers but 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 shell script instead.

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 😅

added 48 characters in body
Source Link
Loading
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.
Source Link
Loading
Source Link
Loading