Will test tomorrow.
We need to post these results in a place where they can be used by normal humans. On Aug 4, 2011, at 10:40 PM, Mark J. Reed wrote: 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>
|