Artificial intelligent assistant

Pipe assigns variable For simplicity I would like to do: echo cart | assign spo; echo $spo Output: cart Does such an `assign` application exist? I am aware of all the ways to do this using substitution.

echo cart | { IFS= read -r spo; printf '%s\
' "$spo"; }


Would work (store the output of `echo` without the trailing newline character into the `spo` variable) as long as `echo` outputs only one line.

You could always do:


assign() {
eval "$1=\$(cat; echo .); $1=\${$1%.}"
}
assign spo < <(echo cart)


The following solutions would work in `bash` scripts, but not at the `bash` prompt:


shopt -s lastpipe
echo cat | assign spo


Or:


shopt -s lastpipe
whatever | IFS= read -rd '' spo


To store the output of `whatever` up to the first NUL characters (`bash` variables can't store NUL characters anyway) in `$spo`.

Or:


shopt -s lastpipe
whatever | readarray -t spo


to store the output of `whatever` in the `$spo` _array_ (one line per array element).

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 72525e869c92a271f459914bc5ce9fbb