Artificial intelligent assistant

zsh assignment failed within piped function There is simple test case local testa=("a") local testb=("b") function test { testb=(${(P)1}) } test "testa" echo "testb="$testb output `testb=a` and local testa=("a") local testb=("b") function test { testb=(${(P)1}) } test "testa" | cat echo "testb="$testb output is `testb=b` I assume that output must be `testb=a` too. What is wrong?

The pipe introduces a subshell in which variable changes are masked from the parent; this is similar to `while` loops involving pipes where variable changes inside that loop do not affect the parent. The PID change can be observed with the `zsh/system` module:


zmodload zsh/system

local testa=("a")
local testb=("b")

function test {
testb=(${(P)1})
echo "INSIDE testb=$testb $sysparams[pid]"
}

test "testa" | cat
echo "OUTSIDE testb=$testb $sysparams[pid]"


Which should show something like


% zsh foo.zsh
INSIDE testb=a 61488
OUTSIDE testb=b 61487
%


different subshell, different variables.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy d3f9cdd6ebe05986810087fe6ce7b9de