bash
Main Topics
Browse All Topicsi have update statement in printf in shell script
printf ("update security set shares = %d, info = \"%s\", shares2= %d where symbol = \"%s\" \ngo\n", Share1, desc, Share2, Symbol ) > out.sql
where i am getting the Share1, Symbol from a text file. but i dont want to update the table if share1 and share2 are blank but update just the desc if not empty update all the 2. There are possibilities with only share1 blank or share2 blank or both blank
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Your requirements are not very clear but it can be done something like ...
if ((Share1 != "") && (Share2 != ""))
{
printf ("update security set shares = %d, info = \"%s\", shares2= %d where symbol = \"%s\" \ngo\n", Share1, desc, Share2, Symbol ) > out.sql
}
else
{
printf ("update security set info = \"%s\" where symbol = \"%s\" \ngo\n", desc, Symbol ) > out.sql
}
Wait, are you guys writing for Bash? Does what you have work? (amit_g also??) I think it would need to look more like:
printf "update security set shares = %d, info = \"%s\", shares2= %d where symbol = \"%s\" \ngo\n" "$Share1" "$desc" "$Share2" "$Symbol" > out.sql
I'm not sure I understand what the conditions are either. I didn't understand the part about "update all the 2" and what happens if one or the other of Share1/2 is blank. Actually I guess I didn't understand the whole thing. Can you reword the requirements?
As I mentioned, your description of the problem is not quite clear but the general structure would be some. the else statement would execute if any of Share1 or Share2 is empty. You can separate them out if needed.
if ((Share1 != "") && (Share2 != ""))
{
printf ("update security set shares = %d, info = \"%s\", shares2= %d where symbol = \"%s\" \ngo\n", Share1, desc, Share2, Symbol ) > out.sql
}
else
{
if (Share1 == "")
{
printf ("update security set info = \"%s\" where symbol = \"%s\" \ngo\n", desc, Symbol ) > out.sql
}
if (Share2 == "")
{
printf ("update security set info = \"%s\" where symbol = \"%s\" \ngo\n", desc, Symbol ) > out.sql
}
}
if ((Share1 != "") && (Share2 != "") && (desc != ""))
{
#update when all have values
}
else
{
if (desc != "")
{
if ((Share1 != "") || (Share2 != ""))
{
#update when desc has value with either Share1 or Share2 empty
}
else
{
#update when desc has value and both Share1 and Share2 empty
}
}
else
{
#update when desc is empty
#Note: this case doesn't care of values in Share1/Share2 but can be added
}
}
Business Accounts
Answer for Membership
by: JimUPosted on 2009-11-04 at 14:22:47ID: 25744679
Which shell is that for?