Escaping a ! in a variable string

Status
Not open for further replies.

LargeSock

Ars Tribunus Militum
2,776
Having lots of trouble with this for some reason. I want to specify a read filter for tshark in a batch file and can't figure out how to escape it.

Here's what I want to do:
Code:
set tshark_options=-n -2 -R (sip.Method == "NOTIFY" && !(sip.Event == "line-seize") && !(sip.Event == "message-summary"))

This would ideally then mean I could do this:
Code:
C:\Users\lgn\Dropbox\scripts\countNOTIFYs>echo %tshark_options%
-n -2 -R (sip.Method == "NOTIFY" && !(sip.Event == "line-seize") && !(sip.Event == "message-summary"))

However, the "!" is being interpreted wrong and I can't figure out how to escape the damn thing:
Code:
C:\Users\lgn\Dropbox\scripts\countNOTIFYs>set tshark_options=-n -2 -R (sip.Method == "NOTIFY" && !(sip.Event == "line-seize") && !(s
ip.Event == "message-summary"))
'!' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\lgn\Dropbox\scripts\countNOTIFYs>set tshark_options=-n -2 -R (sip.Method == "NOTIFY" && ^!(sip.Event == "line-seize") && ^!
(sip.Event == "message-summary"))
'!' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\lgn\Dropbox\scripts\countNOTIFYs>set tshark_options=-n -2 -R (sip.Method == "NOTIFY" && !!(sip.Event == "line-seize") && !!
(sip.Event == "message-summary"))
'!!' is not recognized as an internal or external command,
operable program or batch file.

Anyone have any suggestions? Thanks. This is Win7 cmd.exe.
 

LargeSock

Ars Tribunus Militum
2,776
Still not working that way unfortunately:

C:\Users\lgn\Dropbox\scripts\countNOTIFYs>set tshark_options=-n -2 -R (sip.Method == "NOTIFY" && ^^!(sip.Event == "line-seize") && ^
^!(sip.Event == "message-summary"))
'^!' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\lgn\Dropbox\scripts\countNOTIFYs>echo %tshark_options%
-n -2 -R (sip.Method == "NOTIFY"
 

gusgizmo

Ars Praefectus
3,057
Subscriptor
Code:
C:\Users\gusgizmo>set "tshark_options=-n -2 -R (sip.Method == "NOTIFY" && !(sip.Ev
ent == "line-seize") && !(sip.Event == "message-summary"))"

C:\Users\gusgizmo>set tshark_options

tshark_options=-n -2 -R (sip.Method == "NOTIFY" && !(sip.Event == "line-seize")
&& !(sip.Event == "message-summary"))

C:\Users\gusgizmo>

Works for me, just added quotes. Wasn't paying attention to the command you were using.
 

LargeSock

Ars Tribunus Militum
2,776
[url=http:/civis/viewtopic.php?p=29130875#p29130875:2f4e0tfd said:
sarcastic6[/url]":2f4e0tfd]The reason the quotes work is because it isn't the ! that's the problem, it's the && -- the interpreter things you're giving it a second command to run.

Run this if you don't understand what I'm saying:
Code:
set a=b && dir
Gotcha. That seems sensible. I'm used to a semicolon for a similar purpose in bash but I guess bash actually has && too. Always good to learn something new. Thanks.
 
Status
Not open for further replies.