Skip to content
Advertisement

Iterate Variables of array into command which itself is a variable bash

I am almost there, the “$i” is where I am having trouble. I have tried ${i}, “$i”, $i. I am sure someone with more experience can help me here I have been working on this for 1 full day. Driving me nuts.

JavaScript

Advertisement

Answer

That $i is expanded at the moment you define the sts array. After that, it doesn’t exist.

To make that aws command reusable, use a function:

JavaScript

Note the use of $1 in the function, to retrieve the first argument. The global variable $session_name is still OK


I don’t understand what you’re thinking with the sts array. In the for loop you want to call it as a command, but the configure commands take elements of the array? After all the roles have been assumed? Are you wanting to use the returned data instead?

Do you want:

JavaScript

?

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement