[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] Distinguish between unset and empty variables in loop.
From: |
Greg Wooledge |
Subject: |
Re: [Help-bash] Distinguish between unset and empty variables in loop. |
Date: |
Wed, 23 Nov 2016 12:56:33 -0500 |
User-agent: |
Mutt/1.4.2.3i |
On Wed, Nov 23, 2016 at 05:59:36PM +0100, Christof Warlich wrote:
> But so far, I cannot distinguish
> between empty and unset variables. Here is a stripped-down example what
You can use the ${parameter+word} expansion for this.
imadev:~$ x=''; unset y
imadev:~$ echo "${x+hello}"
hello
imadev:~$ echo "${y+hello}"
imadev:~$
See also http://mywiki.wooledge.org/BashFAQ/083 (or better still, an
older edition of that page... I'm going to have to find the time to
undo all the recent edits that have befouled it).