help-bash
[Top][All Lists]
Advanced

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

Re: feature todo .. be able to unset vars at assignment stage , without


From: Greg Wooledge
Subject: Re: feature todo .. be able to unset vars at assignment stage , without unset util , for coding language fair extendment
Date: Wed, 21 Feb 2024 15:18:12 -0500

On Wed, Feb 21, 2024 at 08:54:30PM +0100, alex xmb sw ratchev wrote:
> say i wanna do major here and there with assigments only

> in bash has three var states
> unset , eg never ever set
> empty , set , but just empty
> filled , non empty set

I believe what he's saying is 'I would like a parameter expansion that
unsets variables, i.e. the opposite of : "${foo=bar}"'.

I could actually see this being useful.  It might offer a syntactically
nicer way of writing

    (unset DISPLAY; some command)

(depending on how it actually ends up working).

As far as the second paragraph goes, I don't think those "three states"
are correct.  As far as bash is concerned, there's no significant
difference between a variable with an empty value, and a variable with
a non-empty value.  The test command and its brethren may differentiate
between those values, but the *states* are the same.

On the other hand, there is a state where a variable has had attributes
defined (e.g. declare -i foo) but has not been created yet (has no value).
The attributes will be applied whenever the variable is actually created
in the appropriate scope.

In code, those would be:

    unset -v foo
    declare -i foo  # or other flags
    foo=            # or a non-empty value



reply via email to

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