Untitled

mail@pastecode.io avatar
unknown
plain_text
6 months ago
586 B
1
Indexable
Never
#!/bin/bash

input_string="v1.10.1@1.28 v1.9.2@1.26"

# Declare an associative array
declare -A version_map

# Split the input string by space and iterate over the values
IFS=" " read -ra values <<< "$input_string"
for value in "${values[@]}"; do
    # Split each value by "@" to get the version and corresponding value
    IFS="@" read -r version v_value <<< "$value"
    
    # Assign the version and value to the associative array
    version_map["$version"]=$v_value
done

# Print the associative array
for key in "${!version_map[@]}"; do
    echo "$key: ${version_map[$key]}"
done
Leave a Comment