Re: Late variable evaluation



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

engeler@xxxxxxxxx wrote:
I thought the process "echo $t" is started anew on each iteration of
the while-loop, and therefore the variable $t read again. $t belongs to
the shell, not to the process?



Given your original statement of the shellcode
t=foo
( while true; do echo $t; sleep 1; done ) &
then your understanding is incorrect.

The code fragment
( while true; do echo $t; sleep 1; done )
will be launched in a subshell, and once that happens, any changes to
variables in the parent shell will not be passed on to the code fragment.

When this fragment is launched, $t has the value of 'foo', and so the subshell
inherits that value for /it's/ version of $t. If you later change the parent
shell's value for $t, the change will not (and cannot) be propogated to the
subshell running the code fragment.

- --
Lew Pitcher

Master Codewright & JOAT-in-training | GPG public key available on request
Registered Linux User #112576 (http://counter.li.org/)
Slackware - Because I know what I'm doing.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)

iD8DBQFEclaNagVFX4UWr64RAnKFAJ9T+qSx3K+u7dOm9MJ8zTCd2DM29ACfYz6L
WBR5tEgZZ3GOxMdWDH8UijI=
=hEio
-----END PGP SIGNATURE-----
.



Relevant Pages

  • Re: Exit errors by subshells are ignored in most shells
    ... make sure that the parent shell exited on errors in the subshell, ... internal set -e command has no effect. ...
    (comp.unix.shell)
  • Re: PID of Background Function
    ... What I do find surprising is ... as 16608 which is actually the PID of its parent shell. ... then that a subshell has no built-in way of knowing its process ID? ...
    (comp.unix.shell)
  • Re: Executing a command in sub-shell
    ... > script and only 1 line of output, ... which is expanded by the shell where it has not been set. ... > expand it dynamically in the subshell, it needs to be quoted in the here ... > its parent shell, so you're out of luck there. ...
    (comp.unix.shell)
  • Re: how to set timeout for read command
    ... > The shell is asked to do a number of things. ... This could take a very long time if the remote machine is not ... > Line 7 kills off the background subshell, ... forward quote before (sleep.... ...
    (comp.unix.shell)
  • Re: alias to the sub shell
    ... :>: A script without a shebang is a new process, not a subshell. ... The shell then is allowed to determine how to process it. ...
    (comp.unix.shell)