[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.
- looping over variables & exporting them at the same time ?, heavy . gear5130, 2024/01/27
- Re: looping over variables & exporting them at the same time ?, Greg Wooledge, 2024/01/27
- Re: looping over variables & exporting them at the same time ?, Paxsali, 2024/01/27
- Re: looping over variables & exporting them at the same time ?, Zachary Santer, 2024/01/28
- Re: looping over variables & exporting them at the same time ?, Greg Wooledge, 2024/01/28
- Re: looping over variables & exporting them at the same time ?, Zachary Santer, 2024/01/29
- Re: looping over variables & exporting them at the same time ?, Greg Wooledge, 2024/01/29
- Re: looping over variables & exporting them at the same time ?, alex xmb sw ratchev, 2024/01/29
- Re: looping over variables & exporting them at the same time ?, Paxsali, 2024/01/29
- Re: looping over variables & exporting them at the same time ?, Paxsali, 2024/01/29
- Re: looping over variables & exporting them at the same time ?,
Greg Wooledge <=
- Re: looping over variables & exporting them at the same time ?, Paxsali, 2024/01/29
- Re: looping over variables & exporting them at the same time ?, Greg Wooledge, 2024/01/29
- Re: looping over variables & exporting them at the same time ?, Zachary Santer, 2024/01/29
- Re: looping over variables & exporting them at the same time ?, Zachary Santer, 2024/01/29