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?

1 Answer 1

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
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.