• 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: Big bug in shell scripting in Applescript
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Big bug in shell scripting in Applescript


  • Subject: Re: Big bug in shell scripting in Applescript
  • From: "Mark J. Reed" <email@hidden>
  • Date: Thu, 04 Aug 2011 18:17:11 -0400

Not a bug, but something you have to be careful with.

sed (and many other CLI tools) is line-oriented.  It only deals with
lines, and expects all its input to have at least one newline (at the
end).

Because of this, bash's "here-string" syntax (<<<'string goes here')
*always appends a newline to the contents of the string*.  Even if the
string already has a newline on the end.

If you want to avoid that, you can use a different construct.  Instead of this:

    do shell script "some command <<<" & (quoted form of myString)

Do this:

    do shell script "echo " & (quoted form of myString) "| some command"



then the command will get a string with *two* newlines at the end.




On Thu, Aug 4, 2011 at 6:08 PM, Zavatone, Alex <email@hidden> wrote:
> Think I found a big bug in sed or shell scripting in AppleScript.
> Copy the code below, run and look at the output.
> \n gets appended to the last line of the return string every time this is
> run.
> on run
> Main()
> end run
> on Main()
> set myString to "abcdefg"
> repeat with myIndex from 1 to 100
> log the length of myString
> set myString to SedNuketheFirstCharIfItIsAPeriod(myString)
> end repeat
> log the length of myString
> end Main
> on SedNuketheFirstCharIfItIsAPeriod(myText)
> set mySuffix to "<<<" & quoted form of myText
> set cmd to "sed 's:^a::'" & mySuffix
> do shell script cmd without altering line endings
> return result
> end SedNuketheFirstCharIfItIsAPeriod
>
> This email message and any attachments are for the sole use of the intended
> recipient(s) and may contain information that is proprietary to U.S.
> Foodservice, Inc and/or its subsidiaries or otherwise confidential or
> legally privileged. If you have received this message in error, please
> notify the sender by reply, and delete all copies of this message and any
> attachments. If you are the intended recipient you may use the information
> contained in this message and any files attached to this message only as
> authorized by U.S. Foodservice. Files attached to this message may only be
> transmitted using secure systems and appropriate means of encryption, and
> must be secured using the same level password and security protection with
> which the file was provided to you. Any unauthorized use, dissemination or
> disclosure of this message or it's attachments is strictly prohibited.
>
>  _______________________________________________
> 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
>
>



--
Mark J. Reed <email@hidden>
 _______________________________________________
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: Big bug in shell scripting in Applescript
      • From: "Zavatone, Alex" <email@hidden>
    • Re: Big bug in shell scripting in Applescript
      • From: "Zavatone, Alex" <email@hidden>
References: 
 >Big bug in shell scripting in Applescript (From: "Zavatone, Alex" <email@hidden>)

  • Prev by Date: Re: Plain text editor
  • Next by Date: Re: Big bug in shell scripting in Applescript
  • Previous by thread: Big bug in shell scripting in Applescript
  • Next by thread: Re: Big bug in shell scripting in Applescript
  • Index(es):
    • Date
    • Thread