Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to print the version of commands #22

Merged
merged 2 commits into from Oct 24, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions shtdlib.sh
Expand Up @@ -347,6 +347,21 @@ function compare_versions {
return $(( lowest_ver_line-1 ))
}

# Prints the version of a command, accepts 1-4 parameters
# 1. Full or relative path to command (required)
# 2. Text to display before version info (optional)
# 3. Flag/Argument to command to get version (optional, defaults to --version)
# 4. Error message if command is not found, to ignore redirect stderr like
hrpatel marked this conversation as resolved.
Show resolved Hide resolved
# this: print_version bash 2> /dev/null
function print_version {
if command -v "${1}" > /dev/null ; then
echo "${2:-}"
${1} "${3:---version}"
else
(>&2 echo "Unable to find command ${1}")
fi
}

# Converts relative paths to full paths, ignores invalid paths
# Accepts either the path or name of a variable holding the path
function finalize_path {
Expand Down