Date: Tue, 27 Oct 2009 11:41:21 -0400 From: carmel_ny <carmel_ny@hotmail.com> To: freebsd-questions@freebsd.org Subject: Using bash with MySQL Message-ID: <BLU0-SMTP742AE1BC94A0883AC0162393B90@phx.gbl>
next in thread | raw e-mail | index | archive | help
I am in the process of writting a script that will use MySQL as a back end. For the most part, I have gotten things to work correctly. I am having one problem though. Assume a data base: database: MyDataBase table: MyTable field: defaults Now, I have populated the 'defaults' fields with the declare statements that I will use in the script. They are entered similar to this: declare -a MSRBL_LIST Now, I issue this from my bash script: SQL_USER=user # MySQL user SQL_PASSWORD=secret # MySQL password DB=MyDataBase # MySQL data base name HOST=127.0.0.1 # Server to connect to NO_COLUMN_NAME="--skip-column-names" COM_LINE="-u${SQL_USER} -p${SQL_PASSWORD} -h ${HOST} ${NO_COLUMN_NAME}" table=MyTable DECLARE_STATEMENTS=($(mysql ${COM_LINE} -i -e"use ${DB}; SELECT defaults FROM "${table}" WHERE 1;")) for (( i=0;i<${#DECLARE_STATEMENTS[*]};i++)); do echo ${DECLARE_STATEMENTS[i]} done This output is produced: declare -a MSRBL_LIST Obviously, I want the output on one line for each field. I have tried enclosing the variables with both single and double quote marks; however, that does not work. Fields that do not contain spaces are displayed correctly. Obviously, I am doing something really stupid here. I hope someone can assist me. I probably should ask this on the MySQL forum; however, I was hoping that someone here might be able to supply a remedy. -- Carmel carmel_ny@hotmail.com |::::======= |::::======= |=========== |=========== | Fraud is the homage that force pays to reason. Charles Curtis, "A Commonplace Book"
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?BLU0-SMTP742AE1BC94A0883AC0162393B90>