I have a long line that comes as output from a git command: a=$(git submodule foreach git status)
. It looks like this:
a = "Entering 'Dir1/Subdir' On branch master Your branch is up to date with 'origin/master'. nothing to commit, working tree clean Entering 'Dir2' HEAD detached at xxxxxx nothing to commit, working tree clean Entering 'Dir3' On branch master Your branch is up to date with 'origin/master'. nothing to commit, working tree clean Entering 'Dir4' On branch master Your branch is up to date with 'origin/master'. nothing to commit, working tree clean"
I want to separate it into an array:
ARR[0] = "'Dir1/Subdir' On branch master ..."
ARR[1] = "'Dir2' HEAD detached at ..."
etc.
To do that, I have tried to substitute "Entering " for a symbol (I have tried # $ % & \t ...) with a=${a//Entering /$}
and it works alright. Then, I try to use IFS and read to separate it into an array: IFS='$' read -ra ARR <<< "$a"
It's here where I am facing problems.
The output that I get of echo ${ARR[@]}
is "Dir1/Subdir1" so I think that read is being affected by spaces or by how the output from git is, but I don't understand what is happening and how to fix it. Could you please give me any suggestions?
Thank you.