On Fri, Jul 12, 2024 at 10:15:02PM -0400, anonymous wrote: > URL: > <https://savannah.gnu.org/bugs/?65981> > > Summary: "bash test -v" does not work as documented with > "export KEY=" > Group: The GNU Bourne-Again SHell > Submitter: None > Submitted: Sat 13 Jul 2024 02:15:01 AM UTC > Category: None > Severity: 3 - Normal > Item Group: None > Status: None > Privacy: Public > Assigned to: None > Open/Closed: Open > Discussion Lock: Any > > > _______________________________________________________ > > Follow-up Comments: > > > ------------------------------------------------------- > Date: Sat 13 Jul 2024 02:15:01 AM UTC By: Anonymous > The documentation of the > [https://www.gnu.org/software/bash/manual/bash.html#Bash-Conditional-Expressions > Bash-Conditional-Expressions] "-v varname" says: > > > -v varname > > True if the shell variable varname is set (has been assigned a value). > > I think "export TEST_EQUAL_WITHOUT_VALUE=" does not assign a value to the > varname, does it?
After the "export", the variable has been *set*. The statement also assigns an empty string to the variable, so it has a value (testing the variable's value against an empty string would yield a boolean true result, showing that there is a value to test with). The "export" is unimportant, it just promotes the shell variable to an environment variable, which isn't relevant to this issue. If you want to test whether a variable contains only an empty string, use "test -z variablename". Note that that does not test whether the variable is *set* though (unset variables expand to empty strings too, unless "set -u" is in effect, in which case it provokes an "unbound variable" diagnostic from the shell). Andreas > Test case: > > docker run -it --rm bash:latest > > export TEST_EQUAL_WITHOUT_VALUE= > > if test -v TEST_EQUAL_WITHOUT_VALUE; then echo "true"; else echo "false"; > fi > > The output is "true", but there is no value assigned to it. > > That is fine to me. I suggest to change the documentation and remove the "(has > been assigned a value)" part. > > > Tested with: GNU bash, version 5.2.26(1)-release (x86_64-pc-linux-musl) > > > > > > > > _______________________________________________________ > > Reply to this item at: > > <https://savannah.gnu.org/bugs/?65981> > > _______________________________________________ > Message sent via Savannah > https://savannah.gnu.org/ -- Andreas (Kusalananda) Kähäri Uppsala, Sweden .