Re: Sourcing a directory of of config files

From: Laurent Bercot <ska-skaware_at_skarnet.org>
Date: Sun, 07 Jul 2024 21:46:49 +0000

>Have a directory "dir/", containing the files "a", "b" and "c", possibly more.
>
>Each file is filled with key=value lines.
>
>Is there an elegant way to source all the files in "dir/" into environment variables of key=value, without writing to a temporary file and sourcing that at the end?

  "cat * | envfile -" ?
  The problem you'll need to solve is this one:

>If "a" and "b" both contain the same key, the value in "b" should overwrite that in "a", but that is probably immanent anyway.

  If you have duplicates, you'll want to determine a sorting order for
the files. If you're happy with regular alphanumeric sorting, then
something like this should work (untested)

(using a loop instead of elglob because cat * won't behave correctly
if dir is empty)

#!/bin/execlineb
importas dir 1
shift
elgetpositionals
emptyenv -c
pipeline
{
   forbacktickx -E -d"\n" file { ls -1 ${dir} }
   cat ${dir}/${file}
}
envfile -
$_at_

--
  Laurent
Received on Sun Jul 07 2024 - 23:46:49 CEST

This archive was generated by hypermail 2.4.0 : Sun Jul 07 2024 - 23:47:19 CEST