Sponsored Content
Top Forums Shell Programming and Scripting Quoting issue: Trouble with bash strings in script Post 302394837 by Bubnoff on Friday 12th of February 2010 10:14:31 PM
Old 02-12-2010
**** 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:
Code:
SQL="SELECT second_id FROM borrower WHERE btype like '"'%wsd%'"'"

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:
Code:
SQL="SELECT second_id FROM borrower WHERE btype like '"'%wsd%'"'"

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:
Code:
$SQSH="/usr/bin/sqsh"
$SERVER="server.whatever.org"
$USER="username"
$PASS="secrets"
$DB="nameOfDatabase"

$SQSH -S "$SERVER" -U "$USER" -P "$PASS" -D "$DB" -C "$SQL" > $OUT

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!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Trouble grepping for multiple strings

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)
Discussion started by: thecoffeeguy
5 Replies

2. Shell Programming and Scripting

BASH quoting behavior

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)
Discussion started by: na5m
5 Replies

3. Shell Programming and Scripting

Bash Script: Trouble unable to run

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)
Discussion started by: rchirico
9 Replies

4. Shell Programming and Scripting

bash: correct quoting with find and exiv2?

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)
Discussion started by: mcframe
4 Replies

5. Shell Programming and Scripting

Find associated strings in a bash shell script

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)
Discussion started by: Sofie
10 Replies

6. Shell Programming and Scripting

Osascript quoting issue

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)
Discussion started by: nextyoyoma
3 Replies

7. Shell Programming and Scripting

Having trouble with My Bash Script, need Help debugging

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)
Discussion started by: jdavis_33
8 Replies

8. Shell Programming and Scripting

Tricky BASH quoting question

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)
Discussion started by: Michael Stora
12 Replies

9. Homework & Coursework Questions

Linux/UNIX Bash Shell Script trouble help needed!!

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)
Discussion started by: TomFord1
4 Replies

10. Shell Programming and Scripting

Help with Bash quoting

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)
Discussion started by: javajockey
4 Replies
RBASH(1)						      General Commands Manual							  RBASH(1)

NAME
rbash - restricted bash, see bash(1) RESTRICTED SHELL
If bash is started with the name rbash, or the -r option is supplied at invocation, the shell becomes restricted. A restricted shell is used to set up an environment more controlled than the standard shell. It behaves identically to bash with the exception that the follow- ing are disallowed or not performed: o changing directories with cd o setting or unsetting the values of SHELL, PATH, ENV, or BASH_ENV o specifying command names containing / o specifying a filename containing a / as an argument to the . builtin command o specifying a filename containing a slash as an argument to the -p option to the hash builtin command o importing function definitions from the shell environment at startup o parsing the value of SHELLOPTS from the shell environment at startup o redirecting output using the >, >|, <>, >&, &>, and >> redirection operators o using the exec builtin command to replace the shell with another command o adding or deleting builtin commands with the -f and -d options to the enable builtin command o using the enable builtin command to enable disabled shell builtins o specifying the -p option to the command builtin command o turning off restricted mode with set +r or set +o restricted. These restrictions are enforced after any startup files are read. When a command that is found to be a shell script is executed, rbash turns off any restrictions in the shell spawned to execute the script. SEE ALSO
bash(1) GNU Bash-4.0 2004 Apr 20 RBASH(1)
All times are GMT -4. The time now is 01:52 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy