Skip to content

Instantly share code, notes, and snippets.

@prcongithub
Last active October 20, 2020 11:50
Show Gist options
  • Save prcongithub/ebd57a320823e01f103cf5e81a135c46 to your computer and use it in GitHub Desktop.
Save prcongithub/ebd57a320823e01f103cf5e81a135c46 to your computer and use it in GitHub Desktop.
Get version for any command without worrying about the parameter to pass
#!/bin/bash
if [ -z "$1" ]
then
echo "Comand Argument Is Missing! Try get_version java"
fi
commands=("--version" "-version" "version" "-v" "-V" "--v")
for i in "${commands[@]}"
do
eval "$1 $i 2>~/.version_output.txt"
status=$?
if test $status -eq 0
then
cat ~/.version_output.txt
exit 0
fi
done
@prcongithub
Copy link
Author

Usage

Download this file and move it to a dir in your $PATH. Recommended /usr/bin

chmod u+x /usr/bin/gv
gv git

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment