fix several unquoted variable uses

Sun, 03 Sep 2023 12:24:39 +0200

author
Mike Becker <universe@uap-core.de>
date
Sun, 03 Sep 2023 12:24:39 +0200
changeset 35
57ea620a54ac
parent 34
4486849e6a6c
child 36
9e386a530bdf

fix several unquoted variable uses

test/make/toolchain.sh file | annotate | diff | comparison | revisions
--- a/test/make/toolchain.sh	Sat Sep 02 19:07:25 2023 +0200
+++ b/test/make/toolchain.sh	Sun Sep 03 12:24:39 2023 +0200
@@ -11,7 +11,7 @@
 
 check_c_compiler()
 {
-	cat > $TEMP_DIR/test.c << __EOF__
+	cat > "$TEMP_DIR/test.c" << __EOF__
 /* test file */
 #include <stdio.h>
 int main(int argc, char **argv) {
@@ -27,8 +27,8 @@
 	return 0;
 }
 __EOF__
-	rm -f $TEMP_DIR/checkcc
-	$1 -o $TEMP_DIR/checkcc $CFLAGS $LDFLAGS $TEMP_DIR/test.c 2> /dev/null
+	rm -f "$TEMP_DIR/checkcc"
+	$1 -o "$TEMP_DIR/checkcc" $CFLAGS $LDFLAGS "$TEMP_DIR/test.c" 2> /dev/null
 	
 	if [ $? -ne 0 ]; then
 		return 1
@@ -38,7 +38,7 @@
 
 check_cpp_compiler()
 {
-	cat > $TEMP_DIR/test.cpp << __EOF__
+	cat > "$TEMP_DIR/test.cpp" << __EOF__
 /* test file */
 #include <iostream>
 int main(int argc, char **argv) {
@@ -54,8 +54,8 @@
 	return 0;
 }
 __EOF__
-	rm -f $TEMP_DIR/checkcc
-	$1 -o $TEMP_DIR/checkcc $CXXFLAGS $LDFLAGS $TEMP_DIR/test.cpp 2> /dev/null
+	rm -f "$TEMP_DIR/checkcc"
+	$1 -o "$TEMP_DIR/checkcc" $CXXFLAGS $LDFLAGS "$TEMP_DIR/test.cpp" 2> /dev/null
 	
 	if [ $? -ne 0 ]; then
 		return 1
@@ -68,14 +68,14 @@
 	if [ -z "$TOOLCHAIN_LD" ]; then
 		return 1
 	fi
-	cat > $TEMP_DIR/test.c << __EOF__
+	cat > "$TEMP_DIR/test.c" << __EOF__
 /* libtest file */
 int main(int argc, char **argv) {
 	return 0;
 }
 __EOF__
-	rm -f $TEMP_DIR/checklib
-	$TOOLCHAIN_LD -o $TEMP_DIR/checklib $CFLAGS $LDFLAGS "-l$1" $TEMP_DIR/test.c 2> /dev/null
+	rm -f "$TEMP_DIR/checklib"
+	$TOOLCHAIN_LD -o "$TEMP_DIR/checklib" $CFLAGS $LDFLAGS "-l$1" "$TEMP_DIR/test.c" 2> /dev/null
 
 	if [ $? -ne 0 ]; then
 		return 1
@@ -87,11 +87,11 @@
 
 for COMP in $C_COMPILERS
 do
-	check_c_compiler $COMP
+	check_c_compiler "$COMP"
 	if [ $? -ne 0 ]; then
-		if [ ! -z "$CC" ]; then
-			if [ $COMP = $CC ]; then
-				echo "$CC is not a working C Compiler"
+		if [ -n "$CC" ]; then
+			if [ "$COMP" = "$CC" ]; then
+				echo "$CC is not a working C compiler"
 				TOOLCHAIN_DETECTION_ERROR="error"
 				break
 			fi
@@ -99,19 +99,19 @@
 	else
 		TOOLCHAIN_NAME=`$TEMP_DIR/checkcc`
 		USE_TOOLCHAIN=$TOOLCHAIN_NAME
-		if [ $COMP = "cc" ]; then
+		if [ "$COMP" = "cc" ]; then
 			# we have found a working compiler, but in case
 			# the compiler is gcc or clang, we try to use
 			# these commands and not 'cc'
 			TOOLCHAIN_NAME=`$TEMP_DIR/checkcc`
-			if [ $TOOLCHAIN_NAME = "gcc" ]; then
+			if [ "$TOOLCHAIN_NAME" = "gcc" ]; then
 				check_c_compiler "gcc"
 				if [ $? -eq 0 ]; then
 					COMP=gcc
 					USE_TOOLCHAIN="gcc"
 				fi
 			fi
-			if [ $TOOLCHAIN_NAME = "clang" ]; then
+			if [ "$TOOLCHAIN_NAME" = "clang" ]; then
 				check_c_compiler "clang"
 				if [ $? -eq 0 ]; then
 					COMP=clang
@@ -126,7 +126,7 @@
 		break
 	fi
 done
-if [ -z $TOOLCHAIN_CC ]; then
+if [ -z "$TOOLCHAIN_CC" ]; then
 	echo "not found"
 fi
 
@@ -134,11 +134,11 @@
 
 for COMP in $CPP_COMPILERS
 do
-	check_cpp_compiler $COMP
+	check_cpp_compiler "$COMP"
 	if [ $? -ne 0 ]; then
-		if [ ! -z "$CXX" ]; then
-			if [ $COMP = $CXX ]; then
-				echo "$CC is not a working C++ Compiler"
+		if [ -n "$CXX" ]; then
+			if [ "$COMP" = "$CXX" ]; then
+				echo "$CXX is not a working C++ compiler"
 				TOOLCHAIN_DETECTION_ERROR="error"
 				break
 			fi
@@ -147,17 +147,17 @@
 		if [ $COMP = "CC" ]; then
 			# we have found a working compiler, but in case
 			# the compiler is gcc or clang, we try to use
-			# these commands and not 'cc'
+			# these commands and not 'CC'
 			TOOLCHAIN_NAME=`$TEMP_DIR/checkcc`
 			USE_TOOLCHAIN=$TOOLCHAIN_NAME
-			if [ $TOOLCHAIN_NAME = "gcc" ]; then
+			if [ "$TOOLCHAIN_NAME" = "gcc" ]; then
 				check_cpp_compiler "g++"
 				if [ $? -eq 0 ]; then
 				   COMP=g++
 				   USE_TOOLCHAIN="gcc"
 				fi
 			fi
-			if [ $TOOLCHAIN_NAME = "clang" ]; then
+			if [ "$TOOLCHAIN_NAME" = "clang" ]; then
 				check_cpp_compiler "clang++"
 				if [ $? -eq 0 ]; then
 				   COMP=clang++
@@ -172,7 +172,7 @@
 		break
 	fi
 done
-if [ -z $TOOLCHAIN_CXX ]; then
+if [ -z "$TOOLCHAIN_CXX" ]; then
 	echo "not found"
 fi
 
@@ -181,21 +181,21 @@
 if [ -z "$TOOLCHAIN_NAME" ]; then
 	TOOLCHAIN_DETECTION_ERROR="error"
 else
-	cat >> $TEMP_DIR/config.mk << __EOF__
+	cat >> "$TEMP_DIR/config.mk" << __EOF__
 # toolchain
 __EOF__
-	echo "CC = ${TOOLCHAIN_CC}" >> $TEMP_DIR/config.mk
-	if [ ! -z "$TOOLCHAIN_CXX" ]; then
-		echo "CXX = ${TOOLCHAIN_CXX}" >> $TEMP_DIR/config.mk
+	echo "CC = ${TOOLCHAIN_CC}" >> "$TEMP_DIR/config.mk"
+	if [ -n "$TOOLCHAIN_CXX" ]; then
+		echo "CXX = ${TOOLCHAIN_CXX}" >> "$TEMP_DIR/config.mk"
 	fi
-	echo "LD = ${TOOLCHAIN_LD}" >> $TEMP_DIR/config.mk
-	echo >> $TEMP_DIR/config.mk
+	echo "LD = ${TOOLCHAIN_LD}" >> "$TEMP_DIR/config.mk"
+	echo >> "$TEMP_DIR/config.mk"
 	
 	cat "make/${TOOLCHAIN_NAME}.mk" > /dev/null 2>&1
 	if [ $? -eq 0 ]; then 
-		echo "include \$(BUILD_ROOT)/make/${TOOLCHAIN_NAME}.mk" >> $TEMP_DIR/config.mk
+		echo "include \$(BUILD_ROOT)/make/${TOOLCHAIN_NAME}.mk" >> "$TEMP_DIR/config.mk"
 	else
-		echo "SHLIB_CFLAGS = -fPIC" >> $TEMP_DIR/config.mk
-		echo "SHLIB_LDFLAGS = -shared" >> $TEMP_DIR/config.mk
+		echo "SHLIB_CFLAGS = -fPIC" >> "$TEMP_DIR/config.mk"
+		echo "SHLIB_LDFLAGS = -shared" >> "$TEMP_DIR/config.mk"
 	fi
 fi

mercurial