I'm trying to print a word from variable with multiple elements using array. Here is a script:
location=($(here mysql query to extract name of locations))
for i in "${location[@]}"; do
echo "$i"
done
But these location name contains spaces: MUMBAI - BORIVALI, DELHI - LAJPATNAGAR and so on. So it prints like: Output in debug mode:
+ for i in '"${LOCATION[@]}"'
+ echo DELHI
DELHI
+ for i in '"${LOCATION[@]}"'
+ echo -
-
+ for i in '"${LOCATION[@]}"'
+ echo LAJPATNAGAR
LAJPATNAGAR
+ for i in '"${LOCATION[@]}"'
+ echo MUMBAI
MUMBAI
+ for i in '"${LOCATION[@]}"'
+ echo -
-
+ for i in '"${LOCATION[@]}"'
+ echo BORIVLI
BORIVLI
I've tried with double quotes:
location=("$(here mysql query to extract name of locations)")
then output is
+ for i in '"${LOCATION[@]}"'
+ echo 'DELHI - LAJPATNAGAR
MUMBAI - BORIVLI'
together.
I want output:
+ echo 'DELHI - LAJPATNAGAR'
DELHI - LAJPATNAGAR
+ echo 'MUMBAI - BORIVLI'
MUMBAI - BORIVLI
IFSto a comma. Please ensure that you show exactly what is produced by mysql.$(here mysql query to extract name of locations)?MUMBAI - BORIVLIandDELHI - LAJPATNAGARas different value in column for better understanding.