Ferguson, Neale writes:
> Strange situation:
>
> #!/bin/sh
> a="1.2.3"
> echo "a="$a
> b=`echo $a | tr -d "."`
> echo "b="$b
> echo $a | tr -d "." | read -e c
> echo "c="$c
>
> I'd expect:
>
> a=1.2.3
> b=123
> c=123
>
> but I get:
>
> a=1.2.3
> b=123
> c=
>
> The builtin function "read" is supposed to read from standard
> input which should be the output stage of the pipe. It works
> the same on Linux 86 but AIX & HP return the expected results.
>
> Any ideas?

It's because the "read" is getting executed in a separate process.
Excerpting from http://www.faqs.org/faqs/unix-faq/faq/part3/section-8.html

   Right, take the next example:

        foo=bar

        echo bletch | read foo

        echo "foo is now: $foo"

      This will print ``foo is now: bar'' in many implementations,
      ``foo is now: bletch'' in some others.  Why?  Generally each part
      of a pipeline is run in a different subshell; in some
      implementations though, the last command in the pipeline is made
      an exception: if it is a builtin command like ``read'', the
      current shell will execute it, else another subshell is created.

      POSIX 1003.2 allows both behaviours so portable scripts cannot
      depend on any of them.

--Malcolm

--
Malcolm Beattie <[EMAIL PROTECTED]>
Linux Technical Consultant
IBM EMEA Enterprise Server Group...
...from home, speaking only for myself

Reply via email to