Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 06-01-2006, 09:11 AM   #1
LQ Newbie
Registered: Oct 2002
Posts: 12

Rep: Reputation: 0
bash variable loses contents in mysql statement

I have a variable $id that contains an id

I can echo it without any problem but...

as soon as I do this
`$mysql "insert into webusers_db(webuserid,db) values('"${id}"','"${db}"')"`

the db gets entered but the id is the default value in my table of zero
I have tried '$id' '"$id"' '"${id}"' '"[${id}]"' '"["${id}"]"' nothing seems to work
Old 06-01-2006, 10:11 AM   #2
Senior Member
Registered: Mar 2004
Location: england
Distribution: Debian, Mint, Puppy, Raspbian
Posts: 3,421

Rep: Reputation: 199Reputation: 199
it's the single quotes, try this:

`$mysql "insert into webusers_db(webuserid,db) values(\'${id}\',\'${db}\')"`
Old 06-01-2006, 10:18 AM   #3
LQ Newbie
Registered: Oct 2002
Posts: 12

Original Poster
Rep: Reputation: 0
alright what I got when I escaped the single 's
ERROR at line 1: Unknown command '\''.

/me scratches his head
Old 06-02-2006, 04:15 AM   #4
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 110Reputation: 110
This should work:
$mysql "insert into webusers_db(webuserid,db) values('${id}','${db}')"
Quoting and escaping is not allways useful or needed


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
BASH IF statement kinetik Programming 10 05-07-2006 02:48 AM
Bash: Print usage statement & exit; otherwise continue using Bash shorthand operators stefanlasiewski Programming 9 02-07-2006 05:20 PM
same system variable, but with different contents? kpachopoulos Linux - General 1 07-31-2005 05:15 PM
bash statement os2 Programming 2 03-20-2005 10:13 PM
get file contents with newlines into bash variable otoomet Linux - Software 2 01-06-2005 01:23 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:32 PM.

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