Created
July 24, 2023 12:43
-
-
Save iron-viper/a767866638f58faf18c388a270a08e9c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Function to convert the version string | |
convert_version_string() { | |
local input_string=$1 | |
local version_number="${input_string#*/v}" # Remove everything before '/v' | |
local version_parts=($(echo "$version_number" | tr '.' ' ')) # Split version string into parts | |
# Ensure we have at least three parts (major, minor, patch) | |
while (( ${#version_parts[@]} < 3 )) | |
do | |
version_parts+=('0') # Append missing parts with '0' | |
done | |
# Print the converted version | |
echo "${version_parts[0]}.${version_parts[1]}.${version_parts[2]}" | |
} | |
# Example usage: | |
input_string="release/v1" | |
converted_version=$(convert_version_string "$input_string") | |
echo "Converted version: $converted_version" | |
input_string="release/v1.2" | |
converted_version=$(convert_version_string "$input_string") | |
echo "Converted version: $converted_version" | |
input_string="release/v1.1.1" | |
converted_version=$(convert_version_string "$input_string") | |
echo "Converted version: $converted_version" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment