My script is like this:#!/bin/bashmysql dbname -N -uroot -p -hhost -se SELECT COUNTRY, COUNTRY_NAME FROM server ORDER BY COUNTRYoutput=$(mysql dbname -N -uroot -p -hhost -se SELECT COUNTRY, COUNTRY_NAME FROM server ORDER BY COUNTRY)echo $outputThe result is like this:Enter password: CN  ChinaCZ  Czech RepublicFI  FinlandJP  JapanNL  NetherlandsRO  RomaniaSG  SingaporeUA  UkraineUS  United StatesUS  United StatesUS  United StatesUS  United StatesEnter 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 StatesI 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?
mysql result to bash variable
bash;mysql
Instead of echo $outputquote it ! Read about word splittingecho $outputDouble quote every literal that contains spaces/metacharacters and every expansion: $var, $(command $var), ${array[@]}, a & b. Use 'single quotes' for code or literal $'s: 'Costs $5 US', ssh host 'echo $HOSTNAME'. Seehttp://mywiki.wooledge.org/Quoteshttp://mywiki.wooledge.org/Argumentshttp://wiki.bash-hackers.org/syntax/words 