My script is like this:
#!/bin/bash
mysql dbname -N -uroot -p -hhost -se "SELECT COUNTRY, COUNTRY_NAME FROM server ORDER BY COUNTRY"
output=$(mysql dbname -N -uroot -p -hhost -se "SELECT COUNTRY, COUNTRY_NAME FROM server ORDER BY COUNTRY")
echo $output
The result is like this:
Enter password:
CN China
CZ Czech Republic
FI Finland
JP Japan
NL Netherlands
RO Romania
SG Singapore
UA Ukraine
US United States
US United States
US United States
US United States
Enter password:
CN China CZ Czech Republic FI Finland JP Japan NL Netherlands RO Romania SG Singapore UA Ukraine US United States US United States US United States US United States
I want to set bash variable output
to be the output of the mysql query, but the output
variable seems to be good except all new lines were stripped away. My question is how to set the bash variable to be the mysql query result with each row in one line?