I'm having trouble adding -j 4
to my make command. Its causing my Bash script to fail with:
./cryptest.sh: line 208: make -j 4: command not found
ERROR: failed to make cryptest.exe
Here's the Bash that determines when to add -j 4
. It seems to mostly be working:
# $MAKE is already set and either 'make' or 'gmake'
CPU=$(cat /proc/cpuinfo | grep -c '^processor')
if [ "$CPU" -gt "1" ]; then
echo "$CPU processors, using \"$MAKE -j $CPU\""
MAKE="$MAKE -j $CPU"
fi
Then, the Bash that invokes it and cause the error:
"$MAKE" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
if [ "${PIPESTATUS[0]}" -ne "0" ]; then
echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
fi
There are similar questions on Stack Overflow with other commands, like Execute command as a string in Bash, but its not obvious to me how to simply append the command's arguments to the command. And doing the obvious results in errors like above, so questions like How can I concatenate string variables in Bash don't seem to work in this instance.
How do I append -j 4
to $MAKE
?
I also tried the following,:
MAKE="$MAKE" "-j $CPU"
But it resulted in:
./cryptest.sh: line 186: -j 4: command not found
Finally, there's 50 to 75 of these:
export CXXFLAGS="..."
"$MAKE" static dynamic ...
So I want to fix 1 "$MAKE"
, and not 50 or 75 uses of it.