wounded in the line of duty
$ cat /tmp/bash-test ; /tmp/bash-test foo #!/bin/bash
if (( $1 >= 0 )) 2>/dev/null; then echo "Argument '$1' is integer" fi
Argument 'foo' is integer
I've used bash's regex support to test for an integer when I was handling options, e.g.:
if [[ $1 =~ ^[0-9]+$ ]] && [[ $1 -gt 0 ]]; then echo "Argument '$1' is integer" fi
More information about formatting options
Pedant alert...
$ cat /tmp/bash-test ; /tmp/bash-test foo#!/bin/bash
if (( $1 >= 0 )) 2>/dev/null; then
echo "Argument '$1' is integer"
fi
Argument 'foo' is integer
I've used bash's regex support to test for an integer when I was handling options, e.g.:
if [[ $1 =~ ^[0-9]+$ ]] && [[ $1 -gt 0 ]]; then
echo "Argument '$1' is integer"
fi