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: Greg Wooledge
Subject: Re: looping over variables & exporting them at the same time ?
Date: Mon, 29 Jan 2024 10:36:52 -0500

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.



reply via email to

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