shell - How to reference bash variables depending on a value of a second variable (dynamic variable usage)? -


this question has answer here:

i kind of stuck on one.

i have 3 preset variables declared in config file defaults.cfg:

android_4.4=android-4.4.4_r1 android_6.0=android-6.0.1_r79 android_7.0=android-7.1.1_r28 

each of these variables contains preferred branch-name building specified android version. how access value of depending on value of android_version.

example how tried it:

#!/bin/bash     source defaults.cfg    android-version=4.4 `repo init -u https://android.googlesource.com/platform/manifest -b ${android_{$android_version}}` 

i can not override indirect value because, should work on jenkins, , jenkins gets 4.4, 6.0, 7.0 , on.

thanks in advance

you can use awk config file value per version:

android_version='4.4' awk -f= -v ver="$android_version" '$1=="android_" ver { print $2 }' config.file  android-4.4.4_r1 

if want pass command use:

repo init -u https://android.googlesource.com/platform/manifest -b \ $(awk -f= -v ver="$android_version" '$1=="android_" ver { print $2 }' config.file) 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -