Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

how to escape @

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 11-10-2006   #1 (permalink)
ktmd
Guest


 

how to escape @

I entered command line below in powershell

sqlcmd -E -S server1 -Q"select @@version"

I got error

Unrecognized token in source text.
At line:1 char:37
+ sqlcmd -E -S hdqncsbysql1 -Q"select @ <<<< @version"

I tried to use ` to escape, but it gives me other issues. I tried single
quote instead of ", it does not help.

how do you fix this?
thanks.
ktmd


My System SpecsSystem Spec
Old 11-11-2006   #2 (permalink)
ktmd
Guest


 

RE: how to escape @

I am confused about how Powershell parses its input. I tried various ways.
the last one works as follows.

this one gives me a continuation promp. Why?
PS C:\temp> sqlcmd -E -S hdqncsbysql1 -Q"select `@@version "
>>


this one works. Why?
PS C:\temp> sqlcmd -E -S hdqncsbysql1 -Q"select `@@version `"



------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------
------------------------------------------------------------
Microsoft SQL Server 2005 - 9.00.2047.00 (Intel X86)
Apr 14 2006 01:12:25
Copyright (c) 1988-2005 Microsoft Corporation
Enterprise Edition on Windows NT 5.2 (Build 3790: Service Pack 1)


(1 rows affected)

"ktmd" wrote:

> I entered command line below in powershell
>
> sqlcmd -E -S server1 -Q"select @@version"
>
> I got error
>
> Unrecognized token in source text.
> At line:1 char:37
> + sqlcmd -E -S hdqncsbysql1 -Q"select @ <<<< @version"
>
> I tried to use ` to escape, but it gives me other issues. I tried single
> quote instead of ", it does not help.
>
> how do you fix this?
> thanks.
> ktmd
>

My System SpecsSystem Spec
Old 11-11-2006   #3 (permalink)
Andrew Watt [MVP]
Guest


 

Re: how to escape @

The following should work:

sqlcmd -E -S server1 -Q 'select @@version'

If you enclose in paired apostrophes the content is taken as literal
which is what, I think, you want here.

If you use paired quotation marks the parser tries to interpret
@@version.

To see the difference try these commands:

$a = 10
"$a"
'$a'

Andrew Watt MVP

On Fri, 10 Nov 2006 20:05:01 -0800, ktmd
<ktmd@discussions.microsoft.com> wrote:

>I entered command line below in powershell
>
>sqlcmd -E -S server1 -Q"select @@version"
>
>I got error
>
>Unrecognized token in source text.
>At line:1 char:37
>+ sqlcmd -E -S hdqncsbysql1 -Q"select @ <<<< @version"
>
>I tried to use ` to escape, but it gives me other issues. I tried single
>quote instead of ", it does not help.
>
>how do you fix this?
>thanks.
>ktmd

My System SpecsSystem Spec
Old 11-11-2006   #4 (permalink)
Andrew Watt [MVP]
Guest


 

Re: how to escape @

On Sat, 11 Nov 2006 05:44:01 -0800, ktmd
<ktmd@discussions.microsoft.com> wrote:

>this one gives me a continuation promp. Why?
>PS C:\temp> sqlcmd -E -S hdqncsbysql1 -Q"select `@@version "
>>>


Hi,

It gives a continuation prompt because you haven't provided a closing
apostrophe.


>this one works. Why?
>PS C:\temp> sqlcmd -E -S hdqncsbysql1 -Q"select `@@version `"


It works because the @@version is enclosed in paired apostrophes so
PowerShell treats that content as literal and doesn't try to interpret
it.

Andrew Watt MVP
My System SpecsSystem Spec
Old 11-11-2006   #5 (permalink)
ktmd
Guest


 

Re: how to escape @

Andrew,
I used the escape character ` , not the aspostrophy ' in my question. that
is why I am confused about the use of the escape character here.

thanks.

"Andrew Watt [MVP]" wrote:

> On Sat, 11 Nov 2006 05:44:01 -0800, ktmd
> <ktmd@discussions.microsoft.com> wrote:
>
> >this one gives me a continuation promp. Why?
> >PS C:\temp> sqlcmd -E -S hdqncsbysql1 -Q"select `@@version "
> >>>

>
> Hi,
>
> It gives a continuation prompt because you haven't provided a closing
> apostrophe.
>
>
> >this one works. Why?
> >PS C:\temp> sqlcmd -E -S hdqncsbysql1 -Q"select `@@version `"

>
> It works because the @@version is enclosed in paired apostrophes so
> PowerShell treats that content as literal and doesn't try to interpret
> it.
>
> Andrew Watt MVP
>

My System SpecsSystem Spec
Old 11-11-2006   #6 (permalink)
Adam Milazzo
Guest


 

Re: how to escape @

I'm also confused.

Andrew Watt [MVP] wrote:
> On Sat, 11 Nov 2006 05:44:01 -0800, ktmd
> <ktmd@discussions.microsoft.com> wrote:
>
>> this one gives me a continuation promp. Why?
>> PS C:\temp> sqlcmd -E -S hdqncsbysql1 -Q"select `@@version "

>
> Hi,
>
> It gives a continuation prompt because you haven't provided a closing
> apostrophe.

But there's no opening apostrophe, so why would it expect a closing one?

>> this one works. Why?
>> PS C:\temp> sqlcmd -E -S hdqncsbysql1 -Q"select `@@version `"

>
> It works because the @@version is enclosed in paired apostrophes so
> PowerShell treats that content as literal and doesn't try to interpret
> it.

There are no apostrophes here either.
My System SpecsSystem Spec
Old 11-11-2006   #7 (permalink)
Adam Milazzo
Guest


 

Re: how to escape @

Andrew Watt [MVP] wrote:
> The following should work:
>
> sqlcmd -E -S server1 -Q 'select @@version'
>
> If you enclose in paired apostrophes the content is taken as literal
> which is what, I think, you want here.
>
> If you use paired quotation marks the parser tries to interpret
> @@version.
>
> To see the difference try these commands:
>
> $a = 10
> "$a"
> '$a'
>
> Andrew Watt MVP


Perhaps I'm not up on the latest PowerShell, but what could @@version
possibly expand to?

In Perl, @ inside a double-quoted string would be a problem, but I
thought all interpolated expressions in PowerShell started with $...?
My System SpecsSystem Spec
Old 11-12-2006   #8 (permalink)
Andrew Watt [MVP]
Guest


 

Re: how to escape @

Hi,

Sorry about that. I misread the back tick as an apostrophe in your
post.

The following behaviour for me was the same on Windows XP SP2 and
Windows 2003 SP1.

When I use the back tick singly (which you say produces a continuation
prompt) I don't see that. I get the SQL Server version.

If I use a second backtick before the closing " (with no space
between) I get a continuation prompt. You say that works.

If I use a second backtick but leave a space before the closing "
(which you say gives a continuation prompt) that works for me.

Did you type what you posted? Or did you cut and paste from lines
which showed the behaviour that you described?

Andrew Watt MVP

On Sat, 11 Nov 2006 07:51:02 -0800, ktmd
<ktmd@discussions.microsoft.com> wrote:

>Andrew,
>I used the escape character ` , not the aspostrophy ' in my question. that
>is why I am confused about the use of the escape character here.
>
>thanks.
>
>"Andrew Watt [MVP]" wrote:
>
>> On Sat, 11 Nov 2006 05:44:01 -0800, ktmd
>> <ktmd@discussions.microsoft.com> wrote:
>>
>> >this one gives me a continuation promp. Why?
>> >PS C:\temp> sqlcmd -E -S hdqncsbysql1 -Q"select `@@version "
>> >>>

>>
>> Hi,
>>
>> It gives a continuation prompt because you haven't provided a closing
>> apostrophe.
>>
>>
>> >this one works. Why?
>> >PS C:\temp> sqlcmd -E -S hdqncsbysql1 -Q"select `@@version `"

>>
>> It works because the @@version is enclosed in paired apostrophes so
>> PowerShell treats that content as literal and doesn't try to interpret
>> it.
>>
>> Andrew Watt MVP
>>

My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
escape key stopped working Alex Vista General 2 08-18-2008 04:11 PM
WebClient, don't want Escape PSApple PowerShell 3 02-18-2008 02:38 PM
Escape character question lawndart PowerShell 2 08-07-2007 01:43 PM
No escape from Norton! varuna21 Vista security 4 04-10-2007 11:46 PM
Escape the $ sign Jay PowerShell 2 02-07-2007 03:09 PM


Update your Vista Drivers Update Your Drivers Now!!

Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008