[PATCH v2 4/5] tests/init.sh: use != test operator instead of -ne

Masatake YAMATO yamato at redhat.com
Sun Nov 19 05:30:24 UTC 2023


In get_config_option(), -ne operator was used to
compare the value extracted from config.h with 0.

Using -ne makes sense if OPTION is defined with "#define".  However,
if it is not defined or explictly undefined with "#undef", an empty
string is passed to -ne as left side operand. This causes an error
in dash and bash:

    % dash
    $ [ -n '' -a '' -ne 0 ]
    dash: 1: [: Illegal number:

    % bash
    $ [ -n '' -a '' -ne 0 ]
    bash: [: : integer expression expected

* tests/init.sh (get_config_option): Use != operand instead of -ne
operator.

Signed-off-by: Masatake YAMATO <yamato at redhat.com>
---
 tests/init.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/init.sh b/tests/init.sh
index a626b92b8..3f0a82f27 100644
--- a/tests/init.sh
+++ b/tests/init.sh
@@ -52,7 +52,7 @@ get_config_option()
 	local opt
 	opt=$(sed -E -n 's/#define[[:space:]]*'"$1"'[[:space:]]*([0-9]+)$/\1/p' \
 		"$CONFIG_H")
-	if [ -n "$opt" -a "$opt" -ne 0 ]; then
+	if [ -n "$opt" -a "$opt" != 0 ]; then
 		printf "%s" "$2"
 	else
 		printf "%s" "${3-}"
-- 
2.41.0



More information about the Strace-devel mailing list