Ash internal 'read' command and pipes

Xabier Oneca -- xOneca xoneca at gmail.com
Wed Oct 9 13:32:03 UTC 2013


2013/10/9 Harald Becker <ralda at gmx.de>:
> $ xyz=abc
> $ ( xyz="test"; )
> $ echo $xyz
> abc
>
> you will see the values of your variables doesn't change when
> commands run in a subshell ... and piping informations always
> means passing data between separate processes, so it forces the
> command to be run in its own subshell.

So,

  $ echo something | read something

is as if written like:

  $ echo something | ( read something )

> Then you may do the following:
>
> $ echo testing | . NAME_OF_YOUR_FILE
>
> shall respond with:
> Now in script
> got value 'testing'
>
> Explanation: The dot command reads the commands from given
> file in the current shell or (in case of pipe) all commands in a
> SINGLE subshell, so the value of variable 'got' may be passed
> from one command to next line of commands.

Same as grouping commands with braces (curly or parenthesis), I suppose...

> If testing with shell commands on Unix, always write all your
> commands in a script and let this script run at once. You can't
> pass in and out variable values between commands as you might
> have done this on Microsoft systems.

Yeah! I know I have to be cautious mostly with variables when I test
commands in the interactive shell. I tried that before posting, in
case the 'interactivity' was messing all.

Very nice explanation. Thanks!

P.S. I am not a Windows guy from at least 6 years now!

--
Xabier Oneca_,,_


More information about the busybox mailing list