[comp.mail.mh] combining scan and pick

wiseb@turing.cs.rpi.edu (G. Bowden Wise) (02/12/91)

Why is it that when I do this:

scan -form scan.appt `pick -datefield Appt-Date -after yesterday +Appts`

it gives me a scan of my +inbox folder when there are no messages from
the pick:

pick: no messages in Appointments
    9               Message 9
   10               Message 10

(9, 10 from my +inbox)

--
--------------------------------------------------------------------
- Bowden Wise
  Computer Science Dept, Rensselaer Polytechnic Inst, Troy, NY 12180
  internet: wiseb@turing.cs.rpi.edu      bitnet: bowden@rpitsmts

wiseb@turing.cs.rpi.edu (G. Bowden Wise) (02/12/91)

It seems that if no messages are generated from the `pick` part of
the command, then it simply scans my current folder.  How can I 
make it not do the scan if no messags qualify from the pick?
--
--------------------------------------------------------------------
- Bowden Wise
  Computer Science Dept, Rensselaer Polytechnic Inst, Troy, NY 12180
  internet: wiseb@turing.cs.rpi.edu      bitnet: bowden@rpitsmts

jerry@ORA.ORA.COM (Jerry Peek) (02/12/91)

In messages <`J_&`&$@rpi.edu> and <~L_&~`$@rpi.edu>, Bowden Wise <wiseb@turing.cs.rpi.edu> wrote:

> Why is it that when I do this:
> 
> scan -form scan.appt `pick -datefield Appt-Date -after yesterday +Appts`
> 
> it gives me a scan of my +inbox folder when there are no messages from
> the pick:
> 
> pick: no messages in Appointments
>     9               Message 9
>    10               Message 10
> 
> (9, 10 from my +inbox)
> 
> It seems that if no messages are generated from the `pick` part of
> the command, then it simply scans my current folder.  How can I 
> make it not do the scan if no messags qualify from the pick?

Like a lot of MH commands, if pick doesn't find any matching messages,
it doesn't change the current folder.  Because your scan doesn't test
to see whether pick failed, it just scans the current folder.

But pick also returns a non-zero exit status if no messages match.
You can test pick's exit status and only scan when the status is zero.

Here's a Bourne shell "if" that will do what you want.  This first example
uses backquotes to store the pick output in a shell variable:

    if msgs="`pick -datefield Appt-Date -after yesterday +Appts`"
    then scan -form scan.appt $msgs
    fi

You can do the same thing but store the messages in an MH sequence:

    if pick -datefield Appt-Date -after yesterday +Appts -seq temp
    then scan -form scan.appt temp
    fi

As long as I'm on a roll :-), here's a csh alias (split onto two lines)
that uses a sequence:

    alias ga 'pick -datefield Appt-Date -after yesterday +Appts -seq temp
	&& scan -form scan.appt temp'

--Jerry Peek, jerry@ora.com