2

I have a gitlab variable as below:

REGIONS: us-east-1 us-west-2 eu-central-1

I want to pass this gitlab variable to a shell script. But when I pass it to script, its fetching only first element and rest are ignored. The code used to pass variable is: test.sh $REGIONS

Is it not possible to pass it like that or is there a way for it. Please help.

3
  • 1
    Is us-east-1 us-west-2 eu-central-1 supposed to be three separate values in an collection or one long value? Commented Sep 24, 2021 at 14:23
  • @Daly: In script it will loop through each regions. If I directly hard code this in code, it works. Commented Sep 24, 2021 at 15:16
  • 2
    Try surrounding the value in quotes Commented Sep 24, 2021 at 15:39

1 Answer 1

1

If REGIONS="us-east-1 us-west-2 eu-central-1", then calling

test.sh $REGIONS

means that

  • us-east-1 will be assigned to the first positional parameter $1
  • us-west-2 will be assigned to $2
  • eu-central-1 will be assigned to $3

All the variables can be get using $@, but a simpler solution would be quoting the variable:

test.sh "$REGIONS"

In this case $1 will contain us-east-1 us-west-2 eu-central-1

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.