I have a script that runs another bash script with N optional parameters, such as:
./my_script.sh --param_1 <value> --param_2 <value> ... --param_N <value>
In my main script, i would like to have N arrays with possible values for each of the N parameters, such as:
PARAM_1_VALS=(1 10 50)
PARAM_2_VALS=(50 10 20)
PARAM_N_VALS=("a" "b" "c")
I'd like to know if there is any function that, given an array of N arrays, returns all the possible combinations among those arrays (ex: (1 50 "a"), (1 50 "b"), ..., (50 20 "c"))
The desired script would be:
all_combinations=get_all_combinations(params_array)
for combination in ${all_combinations[@]}; do
#execute my_script.sh with combination
done
My current solution is performing badly since i'm just iterating through all arrays in nested loops to get all values. I would like to remove the nested loops and look for a better approach.
ps: what i'm looking is very similar to python's itertools.combinations()
solution
Thanks