Reply to comment

Pedant alert...

$ cat /tmp/bash-test ; /tmp/bash-test foo

if (( $1 >= 0 )) 2>/dev/null; then
echo "Argument '$1' is integer"

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"


Please refrain from adding URLs to unrelated or commercial websites. This site is moderated and comments with inappropriate links are rejected. Thank you for your understanding.
The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options