Re: perl regex works differently within a "do shell script" than from within perl
Re: perl regex works differently within a "do shell script" than from within perl
- Subject: Re: perl regex works differently within a "do shell script" than from within perl
- From: Christopher Nebel <email@hidden>
- Date: Fri, 27 Apr 2007 13:25:09 -0700
On Apr 27, 2007, at 12:28 PM, John McKenzie wrote: However, when I put it in an Applescript like so:
set fixedName to do shell script "echo " & stringFromTheClipboard & "| perl -pe s/^\\s+//g;"
fixedName gives me a result of
/Volume s/et cetera/
with trailing spaces also removed, and multiple spaces condensed down to one.
You need to quote "stringFromTheClipboard" -- the shell is seeing each space-separated bit of the original string as a separate parameter, and echo(1) prints exactly one space between them. Do this instead:
set fixedName to do shell script "echo " & quoted form of stringFromTheClipboard & ...
Using "quoted form" is a almost always a good idea when building a "do shell script" command from a variable.
--Chris Nebel AppleScript Engineering
|
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden