On Sat, Jul 26, 2025 at 09:32:27PM +0200, Dan wrote: > I have just fixed things using the let to fix $y behavior in my *pipe > technique* but nothing change: inside the pipe loop variable $arg (or > $arg1 $arg2 $arg3) seems to have a different scope than from outside > the pipe loop (passing by the environment too) ..
the lhs of a pipe will be run in a subshell so it's a complete different process cat /etc/passwd | while read ent;do last_ent="$ent" done echo $last_ent # gone is like cat /etc/passwd | ( while read ent;do last_ent="$ent" done ) echo $last_ent # gone fortunately, your example is a UUOC so you can instead write: while read ent;do last_ent="$ent" done < /etc/passwd echo "ent is $ent (empty by the failed read)" echo "last ent was $last_ent" you can use the result of any abritrary command by using a named fifo rm -rf datastream mkfifo datastream getent passwd > datastream & while read ent;do last_ent="$ent" done < datastream echo "ent is $ent (empty by the failed read)" echo "last ent was $last_ent" rm datastream regards -- Marc Chantreux Pôle CESAR (Calcul et services avancés à la recherche) Université de Strasbourg 14 rue René Descartes, BP 80010, 67084 STRASBOURG CEDEX 03.68.85.60.79
signature.asc
Description: PGP signature