Re: Grab the value of the condition for if.

On Sun, 11 Jan 2009 11:57:24 +0100, Janis Papanagnou
<janis_papanagnou@xxxxxxxxxxx> wrote:

Hongyi Zhao wrote:
Hi all,

Consider the following codes:

$ touch a.dat
$ if [ -f a.dat ] ; then echo a.dat exists. ; fi

In this example, the [ -f a.dat ] should have the value of _true_. My
issue is how can I grab the output value of this condition. Any hints
will be highly appreciated.

In the then/else branches assign constant values to a variable that you
can compare against later; e.g.

if [ -f a.dat ] ; then ov=T ; echo a.dat exists. ; else ov=F ; fi
case $ov in
T) ... ;;
F) ... ;;

A further thought give me the following ideas:
In my mind, when the operator *-f* acts on the *a.dat*, then a inner
logical value, i.e., *T* or *F*, should be generated immediately. I
just want to trap this inner logical value directly instead of using a
roundabout way just as you've given above. Is this possible?


..: Hongyi Zhao [ hongyi.zhao AT ] Free as in Freedom :.