Re: Do shell script with applescript strings containing returns
Re: Do shell script with applescript strings containing returns
- Subject: Re: Do shell script with applescript strings containing returns
- From: Christopher Nebel <email@hidden>
- Date: Mon, 15 May 2006 13:45:12 -0700
On May 15, 2006, at 10:09 AM, Timothy Bates wrote:
Hi there, i'm wanting to send an Applescript string to uniq
(command line
command to remove duplicate lines)
Satimage give this as a working example, but it is now broken. Any
clues on
how to use do shell script with piped strings as input?
Example:
set x to "Reagan
Bush
Clinton
Bush"
do shell script "echo " & x & "|tr '\\r' '\\n'|uniq"
Yes -- quote your strings before giving them to the shell. In this
case:
do shell script "echo " & quoted form of x & "|tr '\\r' '\\n'|uniq"
The above example happens to work in editors that use \r as the line
break character, because the shell doesn't see that as starting a new
line, but fails in ones that use \n (like Script Editor). Quoting is
good policy in any case because of possible meta-characters in the
input, such as "(" or "*".
By the way, that "uniq" command won't change the input -- you'll get
"Reagan, Bush, Clinton, Bush" -- because uniq(1) is defined to only
remove *adjacent* duplicate lines. Try using "sort -u"; if you don't
want to change the order of the original lines, you'll need to get
fancy.
--Chris Nebel
AppleScript and Automator Engineering
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden