Re: Do shell script and special characters
Re: Do shell script and special characters
- Subject: Re: Do shell script and special characters
- From: Chris Espinosa <email@hidden>
- Date: Tue, 22 Oct 2002 13:13:24 -0700
On Tuesday, October 22, 2002, at 11:37 AM, John Delacour
<email@hidden> wrote:
>
> Well, whether it's a "bug" or a design choice is subject to debate.
>
> By definition, shell I/O in Mac OS X is encoded in UTF-8. You can
>
> of course use shell commands to move or copy data between files and
>
> devices in any encoding and in raw form, but to send text to the
>
> shell or get output from it, the defined encoding is assumed to be
>
> UTF-8.
>
>
That's some assumption, since I've never met anyone who types UTF-8,
Well, yes you have. The default text encoding in Terminal is UTF-8;
see Terminal menu, Window Settings dialog, Display pane; the Character
Set Encoding is at the bottom. The Finder and Nav Services encode new
file names that you type into UTF-8, as that's the designated encoding
for file names in the file system; see
http://developer.apple.com/qa/qa2001/qa1173.html. While most Carbon
applications (including Script Editor) still use MacRoman encoding
(when they're in English), the dominant character encoding on Mac OS X
is UTF-8.
>
I use do shell script mainly for perl and I want to be able to write
>
a script in roughly the same way as I would normally; for example
>
the following script will print a bullet.
>
>
#!/usr/bin/perl
>
$_ = qq~"\xA5"~ ;
>
print if /\xA5/ ;
>
# --> <bullet>
Well, when I run this in Jaguar I get the funny diamond character. If,
however, I edit the script (in vi in terminal) and type option-8
instead of \xA5, Terminal shows me:
#!/usr/bin/perl
$_ = qq~""~ ;
print if // ;
# --> <bullet>
and when I run this I get a bullet character on the terminal.
(Incidentally, in vi the bullet shows up as \xe2\x80\xa2 which is the
UTF-8 encoding for the Unicode bullet character)
>
but if I put that into do shell script, I get nothing
>
>
set c to ASCII character 165 -- a mac bullet 0xA5
>
do shell script "perl -e '
>
$_ = qq~" & c & "~;
>
print if /\\xA5/
>
'"
>
--> ""
Well that's a wrong script. Try this:
set c to "" as Unicode text -- a Unicode bullet 0xE280A2
do shell script "perl -e '
$_ = qq~" & c & "~;
print if /" & c & "/
'"
Note that if you run the perl script that uses UTF-8 in the shell and
AppleScript you get the same result. Isn't that what you want?
Chris
_______________________________________________
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.