summaryrefslogtreecommitdiffstats
path: root/scratch/bash-3.1.orig/examples/functions/isnum2
blob: e2e7a5f52c1b3680011c1fda36e800f8084ffae1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
isnum2()
{
	case "$1" in
	'[-+]' | '')	return 1;;	# empty or bare `-' or `+'
	[-+]*[!0-9]*)	return 1;;	# non-digit with leading sign
	[-+]*)		return 0;;	# OK
	*[!0-9]*)	return 1;;	# non-digit
	*)		return 0;;	# OK
	esac
}

# this one handles floating point
isnum3()
{
	case "$1" in
	'')		return 1;;	# empty
	*[!0-9.+-]*)	return 1;;	# non-digit, +, -, or .
	*?[-+]*)	return 1;;	# sign as second or later char
	*.*.*)		return 1;;	# multiple decimal points
	*)		return 0;;	# OK
	esac
}