New answers tagged

1 vote

Test for a number in bash

Depends what you mean by number. 0x12, inf, 1.2, -12, ¹²³, ⑱, 1e6, 1,000,000, Ⅷ, 0x123p-5, 6,23, 0b100110 are all numbers by some definitions of number, and 08, 019, ...
1 vote
Accepted

Test for a number in bash

It is not, as a simple test will show us: #!/bin/bash for var in 1 2 3 a b c; do if [[ "$var" =~ '^[[:digit:]]+$' ]]; then echo "$var is a number" else echo "$var ...
  • 29.3k

Top 50 recent answers are included