help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: looping over variables & exporting them at the same time ?


From: Zachary Santer
Subject: Re: looping over variables & exporting them at the same time ?
Date: Mon, 29 Jan 2024 12:05:49 -0500

On Mon, Jan 29, 2024 at 10:32 AM Paxsali via <help-bash@gnu.org> wrote:

> You must use process substitution here, because using a pipe opens a
> subshell and the variable is lost.
>
Use 'shopt -s lastpipe'. It's been around since Bash 4.2.

>From [1]:
> If set, and job control is not active, the shell runs the last command of
a pipeline not executed in the background in the current shell environment.

I.e.,
printf '%s' "${str}" | mapfile -t -d ' ' arr
would actually populate the arr variable where the rest of the script can
see it.

[1]:
https://www.gnu.org/software/bash/manual/html_node/The-Shopt-Builtin.html


reply via email to

[Prev in Thread] Current Thread [Next in Thread]