bash - Counter for variables combined into separate commands -
i need figure code following scenarios:
i need set packagen , productn variables, should done via loop , counter suppose. based on how many packages , product run corresponding amount of commands. scenario 2 packages , 2 products:
package1=packagea package2=packageb product1=producta product2=productb somecommand --package $package1 --product $product1 somecommand --package $package1 --product $product2 somecommand --package $package2 --product $product1 somecommand --package $package2 --product $product2
this complicated need example 10 packages 10 products , above code not optimal, believe there should easy way how eg:
n=o while true; echo specify package name: read package$n echo have package? read yesno if [[ $yesno = n ]]; break else ((n++)) done
the same loop product, don't know how build above commands based on how many variables have.
packages=( package-1 package-2 package-3 ) products=( product-1 product-2 product-3 ) package in "${packages[@]}" product in "${products[@]}" somecommand --package "$package" --product "$product" done done
Comments
Post a Comment