0

I need to loop through a list of strings, and use each word as parameter for my other functions,

PB_REGION_UPPER=NA,NASA

for region in ${PB_REGION_UPPER//,/}
do
   echo $region
done

I was expecting the result of this to be

NA
NASA

so I can pass NA and NASA separately to other function however the result I got was just

NANASA

isnt supposes to /,/ separate two words here?

Cyrus
  • 84,225
  • 14
  • 89
  • 153
czheng15
  • 11
  • 1
  • 3
    almost ... `//,/` replaces the comma with nothing so you get one string `NANASA` and your code becomes `for region in NANASA; do ...`; try replacing the comma with a space, ie, `${PB_REGION_UPPER//,/ }` so your code becomes `for region in NA NASA; do ...` – markp-fuso May 13 '22 at 19:37
  • keep in mind if your comma-delimited fields contain spaces then those spaces now become delimiters, eg, `PB_REGION_UPPER='NA,NASA,OTHER NASA'` and `${PB_REGION_UPPER//,/ }` becomes `for region in NA NASA OTHER NASA; do ...` => 4 passes through the loop with 4 different values stored in `region` ... `NA`, `NASA`, `OTHER` and `NASA` – markp-fuso May 13 '22 at 19:42

0 Answers0