@@ -2259,6 +2259,12 @@ Checking for integers
tst_is_int "$FOO"
-------------------------------------------------------------------------------
+Checking for integers and floating point numbers
+++++++++++++++++++++++++++++++++++++++++++++++++
+# returns zero if passed an integer or floating point number parameter, non-zero otherwise
+tst_is_num "$FOO"
+-------------------------------------------------------------------------------
+
Obtaining random numbers
++++++++++++++++++++++++
@@ -1,6 +1,6 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0-or-later
-# Copyright (c) Linux Test Project, 2014-2018
+# Copyright (c) Linux Test Project, 2014-2019
# Author: Cyril Hrubis <chrubis@suse.cz>
#
# LTP test library for shell.
@@ -344,6 +344,11 @@ tst_is_int()
return $?
}
+tst_is_num()
+{
+ echo "$1" | grep -Eq '^[-+]?[0-9]+\.?[0-9]*$'
+}
+
tst_usage()
{
if [ -n "$TST_USAGE" ]; then
Using grep -E, which more portable than using awk or anything else. Signed-off-by: Petr Vorel <pvorel@suse.cz> --- doc/test-writing-guidelines.txt | 6 ++++++ testcases/lib/tst_test.sh | 7 ++++++- 2 files changed, 12 insertions(+), 1 deletion(-)