Skip to content

Instantly share code, notes, and snippets.

@dekokun
Created April 16, 2012 09:59
Show Gist options
  • Save dekokun/2397408 to your computer and use it in GitHub Desktop.
Save dekokun/2397408 to your computer and use it in GitHub Desktop.
シェルスクリプトで、引数が0以上の整数であることをチェック
usage()
{
echo $0 hoge
}
if [ -z $1 ]; then
usage
exit
else
expr $1 + 1 >/dev/null 2>&1
fi
if [ $? -ne 1 -a $? -ne 0 ]; then
echo "must be numeric"
exit
elif [ $1 -lt 0 ]; then
echo "must be more than 0"
exit
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment