1

I am having trouble getting IFS to split the string correctly based on the colon delimiter. It seems that the -e inside the string is being considered as an option instead of being considered as a literal string.

#!/bin/bash
string_val="-e:SQA"

IFS=: read -a items <<< "$string_val"

echo "${items[0]}" # Prints empty value
echo "${items[1]}" # Prints SQA

How can this be fixed?

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
agp
  • 363
  • 5
  • 13

1 Answers1

2

The string is being split correctly; the -e in ${items[0]} is treated as an option to echo.

$ string_val="-e:SQA"
$ IFS=: read -a items <<< "$string_val"
$ printf '%s\n' "${items[0]}"
-e
chepner
  • 497,756
  • 71
  • 530
  • 681