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: Deivy Petrescu <email@hidden>
- Date: Mon, 05 Aug 2002 16:49:40 -0400
At 11:49 AM -0700 8/5/02, Christopher Nebel wrote:
>
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.
No, it does not work. There is a bug in do shell script or something
wrong with the sh implementation.
Chris, you are right that AS does whatever it is supposed to do when one writes
set a to "\\b", for instance, but once it gets passed to do shell
script it is passed as \\b.
The difference in behavior between do shell script, do script with
command plus the possible bug with do shell script can be seen
running the following scripts:
set a to "\\b"
set b to "\\\\c"
set c to "\\\\\\d"
set d to "\\\\\\\\e"
set l1 to do shell script "echo " & a
set m1 to do shell script "echo " & a
log a
set l2 to do shell script "echo " & b
set m2 to do shell script "eval echo " & b
log b
set l3 to do shell script "echo " & c
set m3 to do shell script "eval echo " & c
log c
set l4 to do shell script "echo " & d
set m4 to do shell script "eval echo " & d
log d
{{l1, l2, l3, l4}, {m1, m2, m3, m4}}
and
set a to "\\b"
set b to "\\\\c"
set c to "\\\\\\d"
set d to "\\\\\\\\e"
tell application "Terminal"
set l1 to do script with command "echo " & a
set m1 to do script with command "eval echo " & a
log a
set l2 to do script with command "echo " & b
set m2 to do script with command "eval echo " & b
log b
set l3 to do script with command "echo " & c
set m3 to do script with command "eval echo " & c
log c
set l4 to do script with command "echo " & d
set m4 to do script with command "eval echo " & d
log d
end tell
>
>
--Chris Nebel
>
AppleScript Engineering
--
Deivy Petrescu
http://www.dicas.com
_______________________________________________
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.