help-bash
[Top][All Lists]
Advanced

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

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


From: Christof Warlich
Subject: [Help-bash] Solved: Re: Distinguish between unset and empty variables in loop.
Date: Thu, 24 Nov 2016 18:54:37 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0

Just for the record, here is a solution of the problem:

        xxx=hi;
        yyy="";
        unset zzz;
        for i in xxx yyy zzz; do
                (set -o posix; set | grep -q "^$i=") || eval "$i=default"; echo 
$i=${!i};
        done

It prints

        xxx=hi
        yyy=
        zzz=default

as desired.

This is clearly a hack, but it just works, so who cares.

Cheers,

Chris




reply via email to

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