Linux Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsOperating SystemsLinux Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 23rd, 2012, 08:29 AM
ttremain ttremain is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2005
Location: Vancouver, WA, USA
Posts: 364 ttremain User rank is First Lieutenant (10000 - 20000 Reputation Level)ttremain User rank is First Lieutenant (10000 - 20000 Reputation Level)ttremain User rank is First Lieutenant (10000 - 20000 Reputation Level)ttremain User rank is First Lieutenant (10000 - 20000 Reputation Level)ttremain User rank is First Lieutenant (10000 - 20000 Reputation Level)ttremain User rank is First Lieutenant (10000 - 20000 Reputation Level)ttremain User rank is First Lieutenant (10000 - 20000 Reputation Level)ttremain User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Days 7 h 52 m 28 sec
Reputation Power: 188
Backticks

I have a command I need to run from a script, that requires backticks, but I'm not sure how to do that if I need to use backticks around the command itself too.

So I need to run this mysql query (which REQUIRES the backticks around the word Database):

Code:
show databases WHERE `Database` LIKE "central\_%"


Code:
for database in `mysql -Bse 'show databases WHERE `Database` LIKE "central\_%" OR `Database` LIKE "facebook\_%"`
do
  Something
done


Backticks within backticks don't work too well...

Any suggestions?
__________________
Thomas Tremain

Reply With Quote
  #2  
Old November 23rd, 2012, 10:57 AM
salem's Avatar
salem salem is offline
Contributed User
Click here for more information
 
Join Date: Jun 2005
Posts: 3,840 salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 153 Folding Title: Novice Folder
Time spent in forums: 2 Months 3 Weeks 2 Days 20 h 44 m 11 sec
Reputation Power: 1774
> So I need to run this mysql query (which REQUIRES the backticks around the word Database):
But backticks are shell magic.

If your shell is bash, then this seems like it should work.
Code:
for database in $(mysql -Bse 'show databases WHERE $(Database) LIKE "central\_%" OR $(Database) LIKE "facebook\_%")
do
  Something
done


But $(Database) gets evaluated twice, which might be a waste of effort.

So perhaps
Code:
mydb=$(Database)
for database in $(mysql -Bse 'show databases WHERE $mydb LIKE "central\_%" OR $mydb LIKE "facebook\_%")
do
  Something
done
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper

Reply With Quote
  #3  
Old November 23rd, 2012, 12:13 PM
ttremain ttremain is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2005
Location: Vancouver, WA, USA
Posts: 364 ttremain User rank is First Lieutenant (10000 - 20000 Reputation Level)ttremain User rank is First Lieutenant (10000 - 20000 Reputation Level)ttremain User rank is First Lieutenant (10000 - 20000 Reputation Level)ttremain User rank is First Lieutenant (10000 - 20000 Reputation Level)ttremain User rank is First Lieutenant (10000 - 20000 Reputation Level)ttremain User rank is First Lieutenant (10000 - 20000 Reputation Level)ttremain User rank is First Lieutenant (10000 - 20000 Reputation Level)ttremain User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Days 7 h 52 m 28 sec
Reputation Power: 188
I appreciate your efforts there, but that does not meet the requirements.

The backticks around the word Database are NOT to be evaluated by bash, but need to be passed intact as part of the mysql query.

Reply With Quote
  #4  
Old November 24th, 2012, 12:18 AM
salem's Avatar
salem salem is offline
Contributed User
Click here for more information
 
Join Date: Jun 2005
Posts: 3,840 salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 153 Folding Title: Novice Folder
Time spent in forums: 2 Months 3 Weeks 2 Days 20 h 44 m 11 sec
Reputation Power: 1774
I see.

Would something like this work?
Code:
function doit {
    mysql -Bse 'show databases WHERE `Database` LIKE "central\_%" OR `Database` LIKE "facebook\_%"'
}

for database in `doit` ; do 
    echo $database
done
Comments on this post
ttremain agrees: Thanks!

Reply With Quote
  #5  
Old November 24th, 2012, 01:13 AM
ttremain ttremain is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2005
Location: Vancouver, WA, USA
Posts: 364 ttremain User rank is First Lieutenant (10000 - 20000 Reputation Level)ttremain User rank is First Lieutenant (10000 - 20000 Reputation Level)ttremain User rank is First Lieutenant (10000 - 20000 Reputation Level)ttremain User rank is First Lieutenant (10000 - 20000 Reputation Level)ttremain User rank is First Lieutenant (10000 - 20000 Reputation Level)ttremain User rank is First Lieutenant (10000 - 20000 Reputation Level)ttremain User rank is First Lieutenant (10000 - 20000 Reputation Level)ttremain User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Days 7 h 52 m 28 sec
Reputation Power: 188
Yes, that does work...

So does this workaround:
Code:
for database in `mysql -Bse 'show databases'`
do
  if [[ $database =~ ^(facebook|central)\_ ]]
  then
    do something 
  fi
done


The workaround doesn't solve the requirements, but does change them.

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsLinux Help > Backticks

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap