user6505873
user6505873

Reputation:

Unexpected output while splitting an array

I have the following array stored as svc_list delimited by a ':'

declare -a svc_list=Scalability :Warehouse Cloud Solution :Log Analyis :Monitor and Scale :

I am trying to split it with the following bash script (

IFS=':'
for svc in "${svc_list[@]}"
do
  echo $svc
done 

When I execute the script, I only get Scalability.

Can some please let me know what I am doing wrong.

Upvotes: 0

Views: 29

Answers (1)

Barmar
Barmar

Reputation: 781974

That's not the correct syntax to assign an array, you need to put all the array elements in ().

But if you want to split the string into an array using : as the separator, you should start with a string:

svc_string='Scalability :Warehouse Cloud Solution :Log Analyis :Monitor and Scale :'

Then use IFS to split it:

IFS=':'
svc_array=($svc_string)

Upvotes: 1

Related Questions