help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] Distinguish between unset and empty variables in loop.


From: Christof Warlich
Subject: Re: [Help-bash] Distinguish between unset and empty variables in loop.
Date: Wed, 23 Nov 2016 21:26:03 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0

Greg Wooledge wrote:

> Oh. You're doing some bizarre indirection thing.
> You want an associative array instead.

Well, I can't use an associative array, but not because I'm using an old bash version, but because my initial point was that I want to set useful defaults for some _environment_ _variables_ being used by a script:

Christof Warlich wrote:

> I want to set default values to a list of variables if they are unset,
> but leave them untouched otherwise. I want to do this in a loop,
> because the list of variables is rather big.

The variables are part of a script's user interface: They may be set (and, by the way, need to be exported to be visible by the script) by the script's user. AFAIK, (associative) arrays cannot be exported. Furthermore, most of the defaults are just fine for the script in 99% of all use cases, so the user may typically only need to preseed a small subset of these variables. Thus, even if an array _could_ be used, it would make the script's user interface overly complicated.

Anyway, the more I think about this, I fear that that this cannot work, but I'd still be more than happy if someone would come up with some smart idea :-).

Cheers,

Chris







reply via email to

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