> DELETIA
>
>>while read INFORMIXDIR INFORMIXSERVER INFORMIXSQLHOSTS
>>do
>> if [[ -a $INFORMIXDIR && -d $INFORMIXDIR && -r $INFORMIXDIR ]]
>> then
>> if [[ $INFORMIXSQLHOSTS = "" || ( -a $INFORMIXSQLHOSTS || -f \
>>$INFORMIXSQLHOSTS || -r $INFORMIXSQLHOSTS) ]]
>> then
>
>
> Here is the offending line. You have to understand how the && and ||
> operators work. They are not quite ANDs or ORs. Think of the operator
> not as between two statements but as beginning the second statement.
> Now think of || as meaning: "if the current $? is non-zero execute
> the following statement" and && as meaning "execute the following
statement
> if $? is 0"
I know these operators short circuit. Your right about the fact that
it's a flaw in this if-clause.
>
> What you have written is the equivalent of
>
> if test1 && test2 || test3
>
> So let's see what happens:
>
> $ false && echo A || echo B
> B
>
> When the first test is false, and below that would be when
> $INFORMIXSQLHOSTS == "", then the code after the || is executed.
I don't agree with you here, the test below is false when
$INFORMIXSQLHOSTS is not null. "grep -q ^$INFORMIXSERVER[[:space:]]
$INFORMIXSQLHOSTS" will be executed when [[ $INFORMIXSQLHOSTS = "" ]] is
false and/or when "grep -q ^$INFORMIXSERVER[[:space:]]
$INFORMIXDIR/etc/sqlhosts" is false. The mistake is that "grep -q
^$INFORMIXSERVER[[:space:]] $INFORMIXSQLHOSTS" gets executed even if
$INFORMIXSQLHOSTS is null, your right about that, but that's caused by
test2 being false not test1.
> That code is
>
> grep -q ^$INFORMIXSERVER[[:space:]] $INFORMIXSQLHOSTS
>
> But since $INFORMIXSQLHOSTS == "" it becomes
>
> grep -q ^$INFORMIXSERVER[[:space:]]
>
> and that reads, and drains, stdin. Had you placed the
> $INFORMIXSQLHOSTS in quotes, you would have gotten an error
> that would have pointed you in the right direction.
> You should also use quotes on the pattern just to protect yourself
> from errant data.
Thank's for this information.
>
> Your test should be:
>
> if [[ -z $INFORMIXSQLHOSTS ]] && {
> grep -q "^$INFORMIXSERVER[[:space:]]"
"$INFORMIXDIR/etc/sqlhosts" ||
> grep -q "^$INFORMIXSERVER[[:space:]]" "$INFORMIXSQLHOSTS"; }
I think my test should be, with the quotes as you suggest:
if { [[ -z $INFORMIXSQLHOSTS ]] &&
grep -q "^$INFORMIXSERVER[[:space:]]" "$INFORMIXDIR/etc/sqlhosts" } ||
{ [[ -n $INFORMIXSQLHOSTS ]] && grep -q "^$INFORMIXSERVER[[:space:]]"
"$INFORMIXSQLHOSTS" }
This way I grep in the default file $INFORMIXDIR/etc/sqlhosts if
$INFORMIXSQLHOSTS is null as before but grep in the file
$INFORMIXSQLHOSTS only if it's not null thanks to the new [[ -n
$INFORMIXSQLHOSTS ]].
I shall test the code and get back here to tell if it solved the problem.
>
>phrase 'from usenet' in the subject line to avoid spam filtering.
>
>> if [[ $INFORMIXSQLHOSTS = "" ]] && grep -q
>> ^$INFORMIXSERVER[[:space:]] \
>> $INFORMIXDIR/etc/sqlhosts || grep -q ^$INFORMIXSERVER[[:space:]]
>> $INFORMIXSQLHOSTS
>> then
>> PATH=$ORIGINAL_PATH:$INFORMIXDIR/bin
>> mode
>> logs
>> dbspaces
>> checkpoint
>> else
>> if [[ $INFORMIXSQLHOSTS = "" ]]
>> then
>> print "INFORMIXSERVER $INFORMIXSERVER finns inte i
>> $INFORMIXDIR\
>> /etc/sqlhosts"
>> else
>> print "INFORMIXSERVER $INFORMIXSERVER finns inte i
>> $INFORMIXSQLHOSTS"
>> fi
>> fi
>> else
>> print "INFORMIXSQLHOSTS $INFORMIXSQLHOSTS existerar inte, ar
>> inte en \
>> vanlig fil eller du har inte lasrattigheter pa $INFORMIXSQLHOSTS"
>> fi
>> else
>> print "INFORMIXDIR $INFORMIXDIR existerar inte, ar inte en
>>katalog \
>> eller du har inte lasrattigheter pa $INFORMIXDIR"
>> fi
>> done < /opt/bigb/bb/ext/bb-informix.conf
>Opinions expressed herein are my own and may not represent those of my
>employer.