help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] Solved: Re: Distinguish between unset and empty variable


From: Christof Warlich
Subject: Re: [Help-bash] Solved: Re: Distinguish between unset and empty variables in loop.
Date: Thu, 15 Dec 2016 20:47:11 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0

Am 15.12.2016 um 03:36 schrieb Dmitry Alexandrov:
,----[ ./warlich ]
| #!/bin/bash
|
| xxx=hi
| yyy=""
| unset zzz
|
| for v in xxx yyy zzz; do
|     [[ -v $v ]] || printf -v "$v" 'default'
|     printf '%s=%s\n' "$v" "${!v}"
| done
`----

,----
| $ ./warlich
| xxx=hi
| yyy=
| zzz=default
`----
That's definitly much better than my hack, thanks :-).

I would just not have expected that the "unset-ness" of a variable is still available directly through the loops index variable ...



reply via email to

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