Home
Developer Resources
QNX RTOS v4
QNX RTOS v4 Knowledge Base

QNX RTOS v4 Knowledge Base

Foundry27
Foundry27
QNX RTOS v4 project
Resources

QNX RTOS v4 Knowledge Base

Title Problem compiling multiple directories with a shell script
Ref. No. QNX.000009122
Category(ies) Utilities, Development
Issue We've written a small script to compile multiple directories.  The idea is to have a script invoke 'make' in each directory. However, we cannot get the script to halt if there is an error while running make.  Here is the simplest form of the script, which will invoke make in the two directories "chan" and "utils":

for d in chan utils
do
cd ${d} ; make
echo "result = $?"
if test $? -ne 0 then
echo "ERROR!"
break
fi
done

Here is the output that we see:

$  x
<numerous compiler errors here>
cc: /usr/watcom/10.6/bin/wpp386 exited 6
make:  *** [main.o] Error 6
result = 2
make: 'utils.a' is up to date.
result = 0
$

It appears that the echo statament is picking up the correct value value of the $? variable, but the test is failing, as (1) we never see the string "ERROR" on the console, and (2) the break is not being executed.


Solution After this command, the return value in "$?" goes to "0" because "echo" exited successfully.  If this line is removed it will work as expected.  To echo out the errno, put the value of $? into another variable. 

For example:

#!/bin/ksh

result=0

for d in chan utils
do
  cd ${d} ; make
  result=$?
  echo "result $result"
  if test $result -ne 0
  then
    echo "ERROR!"
    exit $?
  fi
done