Hi, I have been doing some scripting lately and have ran into an issue which some of you might help me to solve.
I have the following script:
cat << EOF
#!/bin/bash -e
. $(dirname $0)/000_shared
rm -rf binutils-${BINUTILS_VER} binutils-build
${LOGDIR}/binutils-pass1-${BINUTILS_VER}.log
tar xf ${SROOT}/binutils-${BINUTILS_VER}.tar.bz2
{
time {
mkdir -v binutils-build2
pushd binutils-build
../binutils-${BINUTILS_VER}/configure \
--prefix=/tools \
--with-sysroot=$LFS \
--target=$LFS_TGT \
--disable-nls \
--disable-werror \
--enable-multilib \
--with-lib-path=/tools/lib32:/tools/lib
make
make install
mkdir -v /tools/lib
ln -sv lib /tools/lib64
popd
}
} 2>&1 | tee ${LOGDIR}/binutils-pass1-${BINUTILS_VER}.log
rm -rf binutils-${BINUTILS_VER} binutils-build
EOF
As you can see, bash is invoked with -e parameter, which means
the script will exit on any error.
But, given that I start a kind of a subshell to log the output
of the time builtin, when any of the commands in the time
block exit with an error, the script will just shift itself
after the } 2>&1 .. block, resulting in the rm -rf command
being run even if the, eg, make or make install failed.
So my question is: How to make the script stop completely
when the error happens in the time {} block and not run the
rm -rf commands (and the next script, as the script is invoked
from a bootstrap script which also uses -e).
Or, is there a better way to log the output of the both time
and cmmi commands that doesn't require this kind of a subshell?
Thanks in advance.
--
Note: My last name is not Krejzi.
signature.asc
Description: OpenPGP digital signature
-- http://lists.linuxfromscratch.org/listinfo/lfs-support FAQ: http://www.linuxfromscratch.org/blfs/faq.html Unsubscribe: See the above information page Do not top post on this list. A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing? A: Top-posting. Q: What is the most annoying thing in e-mail? http://en.wikipedia.org/wiki/Posting_style
