bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Interesting problem writing bash script to execute commands from SQL


From: juliodm
Subject: Re: Interesting problem writing bash script to execute commands from SQL
Date: Fri, 29 Aug 2008 07:15:57 -0700 (PDT)



juliodm wrote:
> 
> I'm writing a bash script to that will execute commands from a database.
> What I mean is that the MySQL database contains commands that bash will
> pull and then run itself.
> 
> My problem is that some of the commands contain single quotes, as needed
> by the shell app it plans to run.
> When I write a line like the one below directly in the bash script:
> `myapp -f dosomething -s 'do_some_other_thing -p some_more_things' -l
> end_of_my_line`
> 
> It works fine.... but when I assign it to a variable like:
> COMMAND="myapp -f dosomething -s 'do_some_other_thing -p some_more_things'
> -l end_of_my_line"
> $COMMAND
> 
> Then it will not execute properly.
> I don't know if the spaces inside the single quotes are the problem or if
> the single quotes themselves are the problem.....
> 
> Can anyone give me some clues or another method to use?
> Thanks ahead of time for reading, and possibly giving any assistance.
> Juliodm.
> 
> --UPDATE
> From the terminal......
> bash# myapp -f dosomething -s 'do_some_other_thing -p some_more_things' -l
> end_of_my_line
> 
> works fine... also:
> 
> bash# myapp -f dosomething -s "do_some_other_thing -p some_more_things" -l
> end_of_my_line
> 
> also works fine... with double quotes... but
> 
> from a script:
> MYVAR="myapp -f dosomething -s 'do_some_other_thing -p some_more_things'
> -l end_of_my_line"
> `$MYVAR`
> 
> does not work and...
> 
> MYVAR='myapp -f dosomething -s "do_some_other_thing -p some_more_things"
> -l end_of_my_line'
> `$MYVAR`
> 
> does not work either......
> 
> I get:
> bash# "do_some_other_thing: cannot open shared object file: No such file
> or directory
> 
> or
> bash# 'do_some_other_thing: cannot open shared object file: No such file
> or directory
> 
> depending on wether I used single or double quotes......
> 
> I could really use some help here........
> Can anyone give me some guidance...... please............
> 
> 
> 
> Juliodm.
> 

I finally got it last night. The result was something I thought I tried but
I guess I didn't,
The code is stored in the MySQL DB as:
"myapp -f dosomething -s \'do_some_other_thing -p some_more_things\' -l
end_of_my_line"

Bash retrieves it as:
MYVAR="myapp -f dosomething -s \'do_some_other_thing -p some_more_things\'
-l end_of_my_line"

I strip out the back slashes
then execute using:
`eval $MYVAR`

And it works fine. All the effort that I put into trying to get that tiny
little part of the project working is insane! But ultimately well worth it.

Thank you to Pierre Gaston for trying to help me, unfortunately the link you
provided me comes up broken or it might be blocked by our company
firewall...., and also I just saw it this morning, and as I said, I finally
figured it out last night.

Either way thank you. I appreciate the effort.

-- 
View this message in context: 
http://www.nabble.com/Interesting-problem-writing-bash-script-to-execute-commands-from-SQL-tp19203252p19220802.html
Sent from the Gnu - Bash mailing list archive at Nabble.com.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]