[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Verifying numeric values
From: |
Andy Chu |
Subject: |
Re: Verifying numeric values |
Date: |
Mon, 18 Oct 2021 23:10:32 -0400 |
On Mon, Oct 18, 2021 at 8:44 PM tolugboji via <help-bash@gnu.org> wrote:
>
> Would like to validate a numeric value (from 1 to 255, for use with terminfo).
Try this:
is_valid() {
local x=$1
local b=$(( 1 <= x && x <= 255 ))
return $(( ! b )) # 0 is true, 1 is false
}
$ is_valid 256; echo $?
1
$ is_valid 3; echo $?
0
- Verifying numeric values, tolugboji, 2021/10/18
- Re: Verifying numeric values, David, 2021/10/18
- Re: Verifying numeric values,
Andy Chu <=
- Re: Verifying numeric values, Greg Wooledge, 2021/10/18
- Verifying numeric values, tolugboji, 2021/10/18
- Re: Verifying numeric values, Andy Chu, 2021/10/18
- Re: Verifying numeric values, Greg Wooledge, 2021/10/19
- Verifying numeric values, tolugboji, 2021/10/19
- Verifying numeric values, tolugboji, 2021/10/19
- Re: Verifying numeric values, Andreas Kusalananda Kähäri, 2021/10/19
- Message not available
- Re: Verifying numeric values, Andreas Kusalananda Kähäri, 2021/10/19
- Message not available
- Re: Verifying numeric values, Andreas Kusalananda Kähäri, 2021/10/20
Re: Verifying numeric values, Chris F.A. Johnson, 2021/10/18