Strange action when testing blfs_tool

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


Manuel,
   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.

#!/bin/sh
# A simeple test:::
set -e
V="n"

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

func2() {
   echo "func2"
}

func1
echo "done"
exit
#----END----

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