How to interpret variable but put inside single quotes (in isql -Q option)

How to interpret variable but put inside single quotes (in isql -Q option)

Post by Rick Tuttl » Wed, 28 Jan 1998 04:00:00



I'm using MKS Korn shell on NT and want to execute SQL Server's isql
program with the -Q "query string" option.

ISQL requires that any embedded quotes within the double quotes surrounding
the query string be single quotes.  I have a shell variable that I want to
pass to a stored procedure, but since this needs to be within single quotes
it won't get interpreted by the shell.

E.g., how would I do the equivalent of the following?

var="blue"
isql -S$servername -U$username -P$password -d$database -Q "exec sp_setcolor
'$var' "

and have the stored procedure sp_setcolor sent the parameter 'blue'?

Rick Tuttle

 
 
 

How to interpret variable but put inside single quotes (in isql -Q option)

Post by Dan A. Merc » Wed, 28 Jan 1998 04:00:00


: I'm using MKS Korn shell on NT and want to execute SQL Server's isql
: program with the -Q "query string" option.

: ISQL requires that any embedded quotes within the double quotes surrounding
: the query string be single quotes.  I have a shell variable that I want to
: pass to a stored procedure, but since this needs to be within single quotes
: it won't get interpreted by the shell.

: E.g., how would I do the equivalent of the following?

: var="blue"
: isql -S$servername -U$username -P$password -d$database -Q "exec sp_setcolor
: '$var' "

: and have the stored procedure sp_setcolor sent the parameter 'blue'?

: Rick Tuttle

This will send the parameter 'blue'.  Single quotes inside of
double quotes have no special meaning to the shell - they're just
another character.

--
Dan Mercer

Opinions expressed herein are my own and may not represent those of my employer.

 
 
 

How to interpret variable but put inside single quotes (in isql -Q option)

Post by Fred Su » Thu, 29 Jan 1998 04:00:00



Quote:> ISQL requires that any embedded quotes within the double quotes surrounding
> the query string be single quotes.  How would I do the following:
> var="blue"
> isql -S$servername -U$username -P$password -d$database -Q "exec sp_setcolor
> '$var' "
> and have the stored procedure sp_setcolor sent the parameter 'blue'?

You could experiment with various quoting combinations with eval, and
sooner or later you'll get what you need.

But you might already have what you want!  Here are some ksh[88] samples
that might give you some ideas:

$ TEST=green
$ # Single quotes around this interprets it literally:
$ print '$TEST'
$TEST
$ # ... but compare this (which seems very close to what you're doing now!):
$ print "'$TEST'"
'green'
$ # ... and you can even retain spacing if you quote carefully:
$ eval print "\"   The value of TEST is:  '$TEST'  !\""
   The value of TEST is:  'green'  !

Hope this is of some use.

Fred Surr
Melbourne

 
 
 

1. replace single quote by escaped single quote

Hi

i didn't succeded in replacing a single quote by an escaped one :-/

i do  :

$ a=`cat myfile`
$ echo 'insert into mytable (myfield) values ('$a');" | mysql

the probleme is that 'myfile' can contain single quote not escaped..
like

myfile=rock'n' roll is very good music !

does anyone could help me ?

regards ;-)
mulima

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Article poste via Voila News - http://www.news.voila.fr
Le : Mon Sep  5 18:50:31 2005 depuis l'IP : 82.125.107.96 [VIP 210319158618]

2. ASM Gator CD reader

3. Formattet output inside variable / line brak inside variable

4. I/O SCUD [chipset inition 940P] SCSI controller and RH Linux (5.2)... support?

5. Getting awk (or sed or anything else) to put single quotes into file

6. QMS GDI-Printer under Linux

7. Single quotes in variable

8. Problem when trying to compile kernel with the sound as a module

9. variable interpolation within single quotes

10. replace single quote to double quote with an example

11. Problem in sed using double quotes and single quotes

12. ? about single quote-double quote

13. REGULAR EXPRESSIONS; PERL/AWK/SED; SINGLE QUOTES/DOUBLE QUOTES