I'd like to include a config file in my bash script with 2 conditions: 1) the config file name is constructed on-the-fly and stored in variable, and 2) in case if config file doesn't exist, the script should fail:
config.cfg:
CONFIGURED=yes
test.sh:
#!/bin/sh
$CFG=config.cfg
echo Source command doesn't work here:
[ -f $CFG ] && ( source $CFG ) || (echo $CFG doesnt exist; exit 127)
echo $CONFIGURED
echo ... but works here:
source $CFG
echo $CONFIGURED
What's wrong in [...] statement?