I've scripts like this:
../configure
make
make install
And when I ran the script, even if it fails, it always returns 0. I need it to return the subcommand return code if it fails. How can I achieve that?
Edit: Actual content of the files:
timeout:
#!/bin/bash
timeout 18900 su lfs $@
EXITCODE=$?
echo $EXITCODE
#succeed on timeout
if (( $EXITCODE == 124 ))
then
exit 0
fi
exit $EXITCODE
01:
#!/bin/bash -e
./prepare
echo $LFS
echo $LFS_TGT
echo $PATH
echo $CONFIG_SITE
echo 'int main(){}' > dummy.c && g++ -o dummy dummy.c
if [ -x dummy ]
then echo "g++ compilation OK";
else echo "g++ compilation failed"; fi
rm -f dummy.c dummy
I'm calling it like this: ./timeout ./01 and I get this result:
./1: line 7: dummy.c: Permission denied
g++ compilation failed
And the ./timeout script returns 0;
Edit 2: Tried on a different file, with the same timeout script, and it failed: 11:
#!/bin/bash
./prepare
export MAKEFLAGS='-j2'
cd $LFS/sources
tar -xvf coreutils-8.32.tar.xz
cd coreutils-8.32
case $(uname -m) in
aarch64) patch -Np1 -i ../coreutils.patch
;;
riscv64) patch -Np1 -i ../coreutils.patch
;;
esac
./configure --prefix=/usr \
--host=$LFS_TGT \
--build=$(build-aux/config.guess) \
--enable-install-program=hostname \
--enable-no-install-program=kill,uptime
make
make DESTDIR=$LFS install
mv -v $LFS/usr/bin/chroot $LFS/usr/sbin
mkdir -pv $LFS/usr/share/man/man8
mv -v $LFS/usr/share/man/man1/chroot.1 $LFS/usr/share/man/man8/chroot.8
sed -i 's/"1"/"8"/' $LFS/usr/share/man/man8/chroot.8
rm -rf $LFS/sources/coreutils-8.32
The patch fails, because the file doesn't exist, but the script returns 0.
#!line to indicate a shell?echo. Which one is line 7? The first one?