help-bash
[Top][All Lists]
Advanced

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

Fwd: Undocumented behaviour of 'set -u' - errors when variable IS define


From: #!microsuxx
Subject: Fwd: Undocumented behaviour of 'set -u' - errors when variable IS defined but non-number is used in numeric comparisons
Date: Fri, 15 Nov 2024 20:52:00 +0100

---------- Forwarded message ---------
From: #!microsuxx <fxmbsw7@gmail.com>
Date: Fri, Nov 15, 2024, 8:51 PM
Subject: Re: Undocumented behaviour of 'set -u' - errors when variable IS
defined but non-number is used in numeric comparisons
To: Sabin p <sabin.pla@gmail.com>


try declare -i num=not

=p

On Fri, Nov 15, 2024, 7:03 PM Sabin p <sabin.pla@gmail.com> wrote:

> Hello. Is anyone able to explain why set -u causes the snippet below to
> error out as if var was just not set?
> The intended behaviour is for "$var" -gt 0 to just resolve to false if $var
> is NaN, like it does when the set -u line is cleared.
>
> #!/bin/bash
> set -u
> var=not_a_number
> if [[ "$var" -gt 0 ]]; then
> echo "var is greater than 0"
> fi
> echo "This is never printed because the above snippet crashes with
> message:"
> echo "not_a_number: unbound variable"
>


reply via email to

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