• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: perl regex works differently within a "do shell script" than from within perl
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: perl regex works differently within a "do shell script" than from within perl
      • From: John McKenzie <email@hidden>
References: 
 >Re: Simple Date-Time Format Question... (From: "Nigel Garvey" <email@hidden>)
 >Re: Simple Date-Time Format Question... (From: kai <email@hidden>)
 >perl regex works differently within a "do shell script" than from within perl (From: John McKenzie <email@hidden>)

  • Prev by Date: Re: perl regex works differently within a "do shell script" than from within perl
  • Next by Date: Re: Excel problems switching between documents
  • Previous by thread: Re: perl regex works differently within a "do shell script" than from within perl
  • Next by thread: Re: perl regex works differently within a "do shell script" than from within perl
  • Index(es):
    • Date
    • Thread