2

What is a simple way to split a string and put into an array Here is my string

aa_bb__cc_dd

I would like to have them in an array like this:

array[0] = "aa"

array[1] = "bb"

array[2] = ""

array[3] = "cc"

array[4] = "dd"
1
  • Look at this [solution][1], this exactly has what you're looking for. Just use IFS='_' read -a array <<< "aa_bb__cc_dd" [1]: stackoverflow.com/questions/10586153/… Commented Mar 26, 2013 at 17:32

1 Answer 1

5
var=aa_bb__cc_dd
oldIFS=$IFS
IFS=_
array=($var)
IFS=$oldIFS
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.