<<< Date Index >>>     <<< Thread Index >>>

Re: Automated subscribe/from/record setup script help



On Thu, Oct 30, 2003 at 06:35:34AM -0900, David J. Weller-Fahy wrote:
> * Nicolas Rachinsky <list@xxxxxxxxxxxx> [2003-10-29 23:32]:
> > * "David J. Weller-Fahy" <dave-lists-mutt-users@xxxxxxxxxxxxxxx> 
> > [2003-10-29 11:03 -0900]:
> > > When I start mutt there's a significant lag (mostly because I couldn't
> > > figure out how to select only one file from a given maildir).  Can
> > > anyone suggest a better (faster, more efficient) way to achieve the same
> > > results?
> >
> > $(ls *|head -1) instead of * should help.
> 
> Which * do you mean?  The * in the line beginning with 'FILE='?
> 
> I had something similar to your statement (originally I was using 'ls
> -tr *|sed q' to do what $(ls *|head -1) does).  However, every time I
> started mutt I'd get 'broken pipe: ls' messages for every maildir that
> was empty.  That's why I ended up using echo.
> 
> In example if I use:
> FILE="${DIR}/cur/"`ls -t "$DIR"/cur/ |head -1`
> in place of:
> FILE=`echo "$DIR"/cur/* |sed 's/.\+ //'`
> then I get the broken pipe messages.

Sure enough. If you have very long listing then 'head' will exit after
printing first line and then 'ls' shall get 'broken pipe' error since
nobody reads on the other side.

For your case the slow down comes from ls itself since it takes very
long time to list all the files (IMHO). Consider using 'find'. Also bash
has arrays, so to get first word from listing you may use

VAR=(`ls -t`)
FILE="${DIR}/cur/${VAR[0]}"

After all, consider using perl (or some other scripting tool). Perl has
function readdir that you can call only once to get first available file
name.

Andrei