The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Operating Systems
> Linux Help
|
Backticks
Discuss Backticks in the Linux Help forum on Dev Shed. Backticks Linux Help forum discussing topics including usage, troubleshooting, modules, and distributions. Linux is an open source OS, based on UNIX.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

November 23rd, 2012, 08:29 AM
|
|
Contributing User
|
|
Join Date: Dec 2005
Location: Vancouver, WA, USA
|
|
|
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
|

November 23rd, 2012, 10:57 AM
|
 |
Contributed User
|
|
|
|
> 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
|

November 23rd, 2012, 12:13 PM
|
|
Contributing User
|
|
Join Date: Dec 2005
Location: Vancouver, WA, USA
|
|
|
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.
|

November 24th, 2012, 12:18 AM
|
 |
Contributed User
|
|
|
|
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
|

November 24th, 2012, 01:13 AM
|
|
Contributing User
|
|
Join Date: Dec 2005
Location: Vancouver, WA, USA
|
|
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.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|