Can we pass a gitlab variable with multiple elements to a shell script

Viewed 592

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.

1 Answers

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

Related