• 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 23:40:04 -0400

Sorry, went off on a tangent.  The point is, we've been using <<< as a shortcut for "echo |".  What we need is a shortcut for bash's "echo -n |" - that is, echo with no trailing newline.  The sh equivalent is probably "echo...\c", in which case this should work, but I haven't tried:

do shell script "echo " & (quoted form of myString) & "'\\c' | sed whatever " without altering line endings

Alternatively,

do shell script  "printf %s " & (quoted form of myString) & " | ..."

should also work.

On Thursday, August 4, 2011, Mark J. Reed <email@hidden> wrote:
> The echo command is the shell's print command; a "Hello, world" program in shell looks like this:
>
> echo Hello, World   # "Hello, World"
>
> The pipe symbol "|" takes the output of the left command and feeds it to the right command, so you can make echo work with sed like this:
>
> echo Hello, World | sed s/o//  # "Hell, World"
>
> Which works fine for one-liners.  The problem with this from the standpoint of more significant shell programs is that the command on the right of a pipe is executed in a different shell environment, so it can't have any side effects inside the shell.
>
> For instance, the read command takes a variable name, reads a line of input, and stores the input line in the named variable (creating it if it doesn't exist).  But reading at the end of a pipe does no good because the shell environment in which the variable is set is discarded immediately:
>
> echo Hello, World | read myLine
> echo $myLine # "" - var is not set
>
> The traditional solution is what's called a "here-document", which looks like this:
>
> read myLine <<EOF
> Hello, World
> EOF
> echo $myLine #  "Hello, World"
>
> That's a bit clunky for one-liners, though, so bash added a single-line version called the "here-string":
>
> read myLine <<<"Hello, World"
> echo $myLine  # "Hello, World"
>
> Which is what we've been using a lot in do shell script.
> On Thursday, August 4, 2011, Zavatone, Alex <email@hidden> wrote:
>> Not sure how echo would work with sed.  Remember, I'm new and clueless here.
>
>

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

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