With the following code:
string="[Git status]^functionGitStatus"
IFS='^' read -r -a array <<< "$string"
echo "${array[@]}"
echo "size: '${#array[@]}'"
for e in "${array[@]}"; do
echo "'$e'"
done
It works as expected and shows:
[Git status] functionGitStatus
size: '2'
'[Git status]'
'functionGitStatus'
I did do a research and for example at
is possible use ,
(command with empty space)
If I try to accomplish the same approach:
string="[Git status]^ functionGitStatus"
IFS='^ ' read -r -a array <<< "$string"
echo "${array[@]}"
echo "size: '${#array[@]}'"
for e in "${array[@]}"; do
echo "'$e'"
done
I got:
[Git status] functionGitStatus
size: '3'
'[Git'
'status]'
'functionGitStatus'
sadly not as expected (even when only exists one ocurrence with ^
)
I want to know if is possible to use a complete word-term as separator for example:
string="[Git status]-fn:-functionGitStatus"
IFS='-fn:-' read -r -a array <<< "$string"
echo "${array[@]}"
echo "size: '${#array[@]}'"
for e in "${array[@]}"; do
echo "'$e'"
done
But it shows:
[Git status] u ctio GitStatus
size: '9'
'[Git status]'
''
''
''
''
''
'u'
'ctio'
'GitStatus'
Seems is not possible or perhaps there is a special flag to interpret how complete word-term. If is not possible what other function would help in this scenario?