Source operator doesn't work in if construction in bash
Posted
by Igor
on Stack Overflow
See other posts from Stack Overflow
or by Igor
Published on 2010-05-04T12:32:43Z
Indexed on
2010/05/04
12:38 UTC
Read the original article
Hit count: 289
Hello,
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?
© Stack Overflow or respective owner