Re: How do I escape a question mark (?)
Re: How do I escape a question mark (?)
- Subject: Re: How do I escape a question mark (?)
- From: Christopher Nebel <email@hidden>
- Date: Mon, 5 Aug 2002 11:49:25 -0700
On Sunday, August 4, 2002, at 08:45 PM, Reinhold Penner wrote:
On Sunday, August 4, 2002, at 05:38 , Rob Jorgensen wrote:
On 8/4/02, Reinhold Penner commented:
I need help:
set x to "test.cgi\?"
will not compile (expected """ but found unknown token). What's up
with that? For use in a do shell script, I need to escape a URL that
contains a .cgi? portion. Pasting the URL with the backslashed ?
(\?) works just fine in the Terminal, but I can't pass the URL to
the shell, since AS refuses to compile a string containing "\?". Is
there another way of escaping in either AS or the shell?
Does this work?
set x to "test.cgi\\?"
Unfortunately not:
--> "test.cgi\\?"
This is driving me nuts. I am now at the point where I'm posting the
data. But I really would like to know what the deal is with the ?
You mean you see "test.cgi\\?" in the result window? That's correct.
The trick is that the result window shows you things in source code
form, so you could copy and paste them into a new script. That means
that backslashes get escaped, so you see two backslashes, but there's
really only one in the string. Try "display dialog x" and you'll see
what I mean.
To answer the original question, backslash is how you escape special
characters in an AppleScript string. The possible characters are r, n,
t, \, and ". The first three get interpreted as carriage return,
linefeed (as of 1.5.5, I think), and tab; \ and " are interpreted
literally. Unlike most other languages, AppleScript considers it an
error for anything else to follow a backslash, hence the problem with
"\?". If you want a literal backslash in a string, use "\\". Yes, it
displays oddly, but it works.
Since you're talking about "do shell script", there's another way: use
single quotes around the string. Single quotes suppress all
meta-character interpretation in sh, so you can put anything in them
without anything funny happening. Because getting a single quote is a
bit of a pain (you have to do 'th'\''is'), there's a string property in
1.8.3 to do it for you -- "quoted form". For example:
do shell script "echo " & quoted form of "test.cgi?" --> "test.cgi?"
--Chris Nebel
AppleScript Engineering
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.