Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm looking to get the version number of an app that doesn't have any kind of --version option.

I'm looking for a bash script that will start the process (it runs until killed), grep it's version number and then kill it.

Something like:

./server | grep version | kill $PID

Is that possible?

share|improve this question
Hmmm....what is the application for something like this? and kill what? The thing that runs indefinitely? – mdpc Feb 8 '12 at 0:55
I clarified my question – whatupdave Feb 8 '12 at 1:00
Is this a one time thing or are you going to have to do this many times? – mdpc Feb 8 '12 at 17:09
many times, I'm pulling a file from a remote location and discovering which version it is – whatupdave Feb 9 '12 at 19:23
up vote 6 down vote accepted
./server | grep version | head -n 1 && kill $PID

The head will stop the pipe after it has found 1 result.

If you want to capture the variable you should be able to do:

version=`./server | grep version | head -n 1` && kill $PID
echo $version

Edit: The suggestions for 'strings' is a better path if viable.

share|improve this answer
Or use grep -m 1 and avoid the head -n 1 – Sirex Jan 4 '13 at 0:43

Does the version string follow any reasonable format? You might try running strings against the binary and see if you can build a pattern to match the version string.

Otherwise this gets a little hacky in bash. I'd probably do something like:

./server | grep version &>/tmp/out.$$ &
sleep 10  # <-- however long it takes for version to come out.
kill %1

Edit: Tarrant's answer is much better than mine.

share|improve this answer

Do you actually need to run and kill it this way, or could you find the version by running strings over the binary?


./server | grep user | kill `pgrep -P $$ server`

...should do the trick.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.