2012年3月19日 星期一

Shell check if a variable is a number (Integer)

#!/bin/bash
if ! [[ "${variable}" =~ ^[0-9]+$ ]]
then
    echo "This variable is not a integer"
else
    echo "This variable is a integer"
fi
Reference: http://stackoverflow.com/questions/806906/how-do-i-test-if-a-variable-is-a-number-in-bash

沒有留言:

張貼留言