Re: looping over variables & exporting them at the same time ?
From:
Paxsali
Subject:
Re: looping over variables & exporting them at the same time ?
Date:
Mon, 29 Jan 2024 16:42:54 +0100
Hi Greg,
sorry you got it wrong.
It's minus d single quote space single quote, not minus d single quote
single quote.
It works as intended. By using copy and paste you can check.
Greg Wooledge <greg@wooledge.org> schrieb am Mo., 29. Jan. 2024, 16:37:
> On Mon, Jan 29, 2024 at 04:31:48PM +0100, Paxsali via wrote:
> > str='a * ! d';
> > mapfile -t -d ' ' arr < <(printf '%s' "${str}");
> > declare -n arr
> >
> > declare -a arr=([0]="a" [1]="*" [2]="!" [3]="d")
> >
> > ...also does the trick without the unnecessary quoting/escaping, unless
> > that's really what you want.
>
> Just be aware that this one will treat *each* space character as a
> separate delimiter.
>
> unicorn:~$ mapfile -t -d ' ' arr < <(printf %s 'a * ! d')
> unicorn:~$ declare -p arr
> declare -a arr=([0]="a" [1]="*" [2]="" [3]="" [4]="!" [5]="d")
>
> This may or may not be what's wanted. The version I used originally,
> with read, treats each *group* of spaces as a single delimiter.
>
>