This commit is contained in:
2025-10-16 18:05:27 +02:00
parent 900801e27c
commit cf76b4e7c3

View File

@@ -13,7 +13,8 @@
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Replace @VAR@ in a text file by the corresponding $VAR value # Replace @VAR@ in a text file by the corresponding $VAR value
# The --delimiter or -d option allow to use something else than @ # The --delimiter or -d option allow to use something else than @
setvar() { setvar()
{
local delimiter="@" local delimiter="@"
local vars=() local vars=()
local file local file
@@ -27,7 +28,7 @@ setvar() {
;; ;;
-*) -*)
prnt E "setvar(): Unknown option: $1" prnt E "setvar(): Unknown option: $1"
die die 7
;; ;;
*) *)
if [[ -f $1 && $# -eq 1 ]]; then if [[ -f $1 && $# -eq 1 ]]; then
@@ -42,11 +43,11 @@ setvar() {
if [[ -z $file ]]; then if [[ -z $file ]]; then
prnt E "Usage: setvar [--delimiter D] VAR1 [VAR2 ...] <file>" prnt E "Usage: setvar [--delimiter D] VAR1 [VAR2 ...] <file>"
die 1 die 7
fi fi
if [[ ${#vars[@]} -eq 0 ]]; then if [[ ${#vars[@]} -eq 0 ]]; then
prnt E "No variable name(s) provided." prnt E "No variable name(s) provided."
die 1 die 7
fi fi
local var val escaped pattern local var val escaped pattern
@@ -73,7 +74,8 @@ export -f setvar
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Replace @VAR@ in a text file by the corresponding values available in the # Replace @VAR@ in a text file by the corresponding values available in the
# environment. The --delimiter or -d option allow to use something else than @ # environment. The --delimiter or -d option allow to use something else than @
setvars_from_env() { setvars_from_env()
{
local file delimiter="@" local file delimiter="@"
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
case "$1" in case "$1" in
@@ -90,7 +92,7 @@ setvars_from_env() {
[[ -f $file ]] || { [[ -f $file ]] || {
prnt E "File not found: $file" prnt E "File not found: $file"
die 1 die 10
} }
local vars local vars