LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-13-2006, 03:24 PM   #1
carriehoff
LQ Newbie
 
Registered: Jul 2006
Posts: 9

Rep: Reputation: 0
Syntax error?


Could somebody please help me?

I can run each of these SELECT commands from the command line at mysql prompt, but when I try to run as a shell script I get an error (see below)

Code:
#!/bin/bash
echo starting to get all current mls records
mysql db --user=uname <<**
SELECT `MLS No` from idx_4 into outfile '/tmp/idx4.txt' ;
SELECT `MLS No` from idx_5 into outfile '/tmp/idx5.txt' ;
exit
**
echo finished getting mls numbers
/usr/local/mlsrecs.sh: Line 3: MLS: command not found
/usr/local/mlsrecs.sh: Line 3: MLS: command not found
Error 1064 (42000) You have an error in your syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from idx_4 into outfile '/tmp/idx4.txt'' at line 1

I can't figure out what the problem is. Can anybody else see it?
 
Old 07-13-2006, 03:35 PM   #2
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
The problem is that you're using backticks (`), which tell the shell to replace the command between them with the output of that command. Clearly that isn't what you want - it looks like you want to get the data from a column called "MLS No" in those tables. Can you even have column names with spaces in? It's been a while since I've done any SQL, but perhaps you can enclose those in normal single quotes (i.e. 'MLS No'), or double quotes ("MLS No").
 
Old 07-13-2006, 03:37 PM   #3
carriehoff
LQ Newbie
 
Registered: Jul 2006
Posts: 9

Original Poster
Rep: Reputation: 0
Backticks?

I didn't even think backticks would be the problem. Why does it work from the command line with backticks in mysql shell, but in shell script it needs single quotes? Kind of quirky, but will make a note of it.

Thanks,
Carrie
 
Old 07-13-2006, 04:35 PM   #4
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,568

Rep: Reputation: 164Reputation: 164
Before your selects are passed to mysql, they're parsed by the shell. `` are signs showing that a command should be run. So that's why you have your problem.
 
Old 07-13-2006, 04:41 PM   #5
carriehoff
LQ Newbie
 
Registered: Jul 2006
Posts: 9

Original Poster
Rep: Reputation: 0
Not workin

Well, if I replace the backticks with single quotes or double quotes
Code:
#!/bin/bash
echo starting to get all current mls records
mysql db --user=uname <<**
SELECT `MLS No` from idx_4 into outfile '/tmp/idx4.txt' ;
SELECT `MLS No` from idx_5 into outfile '/tmp/idx5.txt' ;
exit
**
echo finished getting mls numbers
I get a text file full of this: MLS #, instead of the actual value of the field.
The field name has a space in it. What is the proper syntax for a field name with a space in it? or is it possible to use a variable?

Carrie
 
Old 08-07-2006, 04:03 PM   #6
carriehoff
LQ Newbie
 
Registered: Jul 2006
Posts: 9

Original Poster
Rep: Reputation: 0
Please help

I still have not resolved this problem. Can anybody tell me the proper syntax for this code that does not work from a bash script file:

#!/bin/bash
echo starting to get all current mls records
mysql dbname --user=uname <<**
SELECT `MLS #` from idx_1 into outfile '/tmp/idx_1.txt';
SELECT `MLS No` from idx_2 into outfile '/tmp/idx_2.txt';
SELECT `MLS No` from idx_3 into outfile '/tmp/idx_3.txt';
SELECT `MLS No` from idx_4 into outfile '/tmp/idx_4.txt';
SELECT `MLS No` from idx_5 into outfile '/tmp/idx_5.txt';

Backticks don't work, double and single quotes won't produce the right results, and I've also tried brackets and curvy brackets with no success.

What is the proper syntax within the bash script for a MySQL statement with a space in the fieldname?

Thanks,
Carrie
 
Old 08-07-2006, 05:15 PM   #7
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,568

Rep: Reputation: 164Reputation: 164
Not quite sure of that, but I'd do it this way:
Code:
mysql dbname --user=uname <<**
SELECT \`MLS #\` from idx_1 into outfile \'/tmp/idx_1.txt\';
SELECT \`MLS No\` from idx_2 into outfile \'/tmp/idx_2.txt\';
SELECT \`MLS No\` from idx_3 into outfile \'/tmp/idx_3.txt\';
SELECT \`MLS No\` from idx_4 into outfile \'/tmp/idx_4.txt\';
SELECT \`MLS No\` from idx_5 into outfile \'/tmp/idx_5.txt\';
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
c++ syntax error...HELP!! lmvent Programming 3 09-30-2005 03:40 PM
Syntax error phernand Programming 1 05-10-2005 01:04 PM
Many errors when 'make'ing (example: error: syntax error before `::' token) darkblade Linux - Software 5 03-02-2005 04:00 PM
C++ syntax error before :: token HELP, i cant find the syntax error :( qwijibow Programming 2 12-14-2004 07:09 PM
ERROR running make when installing Nvidia drivers (syntax error) randyriver10 Linux - Software 5 02-21-2004 05:51 PM


All times are GMT -5. The time now is 04:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration