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: Emmanuel <email@hidden>
- Date: Mon, 15 May 2006 23:52:04 +0200
At 1:45 PM -0700 5/15/06, Christopher Nebel wrote:
On May 15, 2006, at 10:09 AM, Timothy Bates wrote:
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.
Timothy was not completely accurate when quoting Satimage. The
example[1] really reads:
set x to "Reagan
Bush
Clinton
Bush"
do shell script "echo " & x & "|tr '\\r' '\\n'|sort|uniq"
(and it does work in editors that use \r etc.)
[1] <http://www.satimage.fr/software/en/unix_code.html>
Emmanuel
Satimage
_______________________________________________
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