[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: fastest way to copy a bash array to a file
From: |
Dennis Williamson |
Subject: |
Re: fastest way to copy a bash array to a file |
Date: |
Wed, 12 Jul 2023 22:46:20 -0500 |
On Wed, Jul 12, 2023, 10:15 PM Budi <budikusasi@gmail.com> wrote:
> How fastest, simplest way to copy or write a bash array values to a file
> e.g.
>
> m=( foo bar baz )
>
> printf '%s\n' "${m[@]}" >test
>
>
> Is there/what'd be faster way by use of binary utility instead of
> redirection ?
>
The command you show is outputting a string to a file. The string is the
expansion of the array. Does the resulting file contain what you want? If
so then you can't get any better than what you have.
However if you want to actually have the file contain something that can be
easily turned back into an array then you could try
declare-p m > test
Then you could source that file to get the array back
unset m
. test