Quoting issue: Trouble with bash strings in script
I can do this on the command line:
I can also just leave the SQL at the end intact on one line ....
... However, when I throw this in a script like:
When I run the script I get the SQSH help page. So my question is whether
this is an oddity of bash quoting or a weird sqsh thing.
You can do stuff like this with isql by piping the string or using here
docs. sqsh uses the -C option to allow the SQL at the end. sqsh is much better for the most part, but I can't get the string part to work. I've tried numerous quoting combos. I've already looked at the sqsh man page more
than I care to mention. Is this my bash ignorance or a limitation of sqsh?
I gotta go do something else before I throw myself under a train.
**** UPDATE ~ binlib points out an easier ( more correct ) way to quote the expression in the post following this one. ******
How do I hide quotes from sqsh and pass the SQL?
---------- Post updated at 06:58 PM ---------- Previous update was at 06:02 PM ----------
Solution ....finally.
Problem:
Protect quoted expression "%wsd%" from bashes prying eyes. sqsh must see it in quotes.
Answer:
Victory is sweet. Now if I could just get out of this damn valentines banquet I get
conned into every year .....[SIGH]
Thanks ~
Bub
PS: sqsh rocks if you need to deal with Sybase or MS SQL server.
---------- Post updated at 07:14 PM ---------- Previous update was at 06:58 PM ----------
I've seen other SQSH users in this mess while Googling, so here's a tip for
passing queries to SQSH without resorting to external SQL scripts.
Define your query:
Note carefully the quoting in the expression %wsd%. The expression is surrounded by single quoted double quotes: eg., '"'
while the whole query is surrounded by single quotes ...making
for a quote mess on the end ...eg., '"'" ( thats: single - double - single - double ).
***** EDIT ***** Please see the following two posts ...esp. from Binlib. You can quote the last expression with a single set of single quotes.
Thanks binlib! Tested and true.
Next, run that filthy query like so:
You don't necessarily need all the variables, but it's a bit easier on
the eyes of those stuck reading it later. I usually define the sqsh
binary for cron, otherwise you'd likely have to define it for the
cron environment. Could be mistaken ...I always try to cron-proof
all but the most common commands. Easier than fixing every cron
environment path variables.
Later ...
Bub
***** UPDATED **** Please see following two posts for simpler quoting option.
Last edited by Bubnoff; 02-15-2010 at 02:43 AM..
Reason: Red herring: single quotes work. It was an issue in the way I declared sqsh. Damn I hate that!
is one argument made of three parts:
quoted by double quotes, followed by
quoted by single quote, followed by
quoted by double quotes.
Since the %wsd% part doesn't need to be single quoted, it can be simply embedded with the other parts. As in
which is simpler. In fact, it even works if you want the wsd part to be a variable. On the other hand, if the wsd part has dollar signs, then your method of single quoting it is better.
...it worked. This coincided with the last quoting concoction
I had tried ...thus I mistakenly concluded that it was the
quoting that fixed it.
This issue was strange because sqsh was running but complaining about
syntax errors in the options. So basically I was chasing the proverbial
'red herring'.
I thought that the 'declare -rx' syntax was perfectly legal. I have used this
form before with no issues. I sync with rsync this way. I wonder what the deal is with sqsh?
I am trying to write a BASH script that will prompt a user to enter a number of days, then calculate the date.
My problem is the date command uses single or double quotes. For Example..
date -d "7 days"
Here is an example of some same code I am trying to work through.
echo "when do you... (4 Replies)
Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
2. Shell Bash Script
3.
!/bin/bash
if
echo no directory
then
mkdir -p /home/AC_Drywall
elif ; then
echo "$dir already exist"
fi (4 Replies)
I have some data files that I can identify by a certain pattern in the names using find.
Every one of those data files has an XML file associated with it (can be multiple data files per XML file).
The XML file is always up one directory from the data file(s) in a folder calledRun##### -... (12 Replies)
Hello Friends
I am having trouble with my script below. I will describe the problems below the code box. I am hoping that some of the experts here can help me.
#!/bin/bash
#=========================================================================================================
# Rsync File... (8 Replies)
I am at a loss on this one. I am trying to run this command on a bunch of (OS 10.7.4) macs:osascript -e "tell application \"System Events\" to return name of every process whose frontmost is true"
On some, it works fine. On others, I get this error:
I have also tried (note the single quotes):... (3 Replies)
Hi together,
unfortunately I am not a shell script guru - the following might touch
the depths of awk, substr, split, regexps, where I am still fighting with - but as always the boss needs a fast solution :-(
So: I have the following USER/PASSWORD-installation-config-file, from where I want to... (10 Replies)
Hi,
I need to embed a metatag to image files which contain qrcodes, i usually do this with exiv -M "set Exif.Image.DocumentName `zbarimg -q -Sdisable -Sqrcode.enable --raw image.tif`" image.tif
which works fine. However I need to do this recursivly for whole directory and subdiretory... (4 Replies)
I am trying to create a menu, and the script fails on ln 38 (Files in pwd). Any idea on where the problem is??
Thanks for the help
Rob
#!/bin/bash
# Cool Script for Weekly Assignment 2 (#3) that creates a menu to act as a ui
# and run some popular commands.
clear
while :
do ... (9 Replies)
The block below isn't a surprise:$ ls
file1 file2 file3
$ x=*
$ echo $x
file1 file2 file3
$ echo '$x'
$x
$ echo "$x"
*
$But I found this block a bit bewildering:$ echo $x'
>'
*
$I'm wondering why substitution wasn't performed on the $x, since it was unquoted (as far as I can tell).... (5 Replies)
I am having a heck of a time trying to write a script that will grep for multiple strings in a single file. I am really at my wits end here and I am hoping to get some feedback here.
Basic information:
OS: Solaris 9
Shell: KSH
Oracle Database server
I was trying to grep through a file... (5 Replies)