Strange action when testing blfs_tool

George Boudreau georgeb at
Tue Aug 29 18:12:59 PDT 2006

   It took a while to remember, somewhere in the past I happened on a 
similar problem.
  [[ $BLFS_TOOL = "y" ]] && action
   This doesn't cause a problem unless you enable error trapping and 
then the script dies.

  When BLFS_TOOL is not set bash does the comparison, it is not true and 
the next command it finds is the termination of the function '}'. If you 
put any command between the test and the '}' everything is fine.

  This is a head scratcher if you have never seen it before.

# A simeple test:::
set -e

func1() {
  echo "func1"
  [[ ${V} = "y" ]] && func2

func2() {
   echo "func2"

echo "done"

1. The script prints "func1" only .. where is the "done"?
2. Turn off error trapping, set +e
    script prints "func1" "done" (what you would expect)
3. Turn error trapping back on, set -e
    Insert a null command, : ,before the closing } in func1
    script prints "funct1" "done"

More information about the alfs-discuss mailing list