[NTLUG:Discuss] Auto-completion within a bash script?

Lance Simmons simmons.lance at gmail.com
Thu Apr 16 11:17:56 CDT 2009


I wrote this _very_ rudimentary script for sending emails to
different groups of my students and colleagues:

> #!/bin/sh
> echo File to attach:
> read ATTACHMENT
> echo "You are attaching $ATTACHMENT"
> echo List of addresses:
> read ADDRESSES
> echo "Your addresses are in $ADDRESSES"
> echo File with message:
> read MESSAGE
> echo "Your message is in $MESSAGE"
> echo Subject line:
> read SUBJECT
> echo "Your subject is" \""$SUBJECT"\"
> CHECK=""
> if [ "$CHECK" = "$ATTACHMENT" ]; then
>   for i in `cat $ADDRESSES | cut -d \  -f 1`;
>    do mutt -s "$SUBJECT" "$i" < "$MESSAGE";
>    sleep 20;
>   done
>  else
>   for i in `cat "$ADDRESSES" | cut -d \  -f 1`;
>    do mutt -a "$ATTACHMENT" -s "$SUBJECT" "$i" < "$MESSAGE";
>    sleep 20;
>    done
> fi
> exit 0

Don't laugh; I said it was rudimentary.  Here's my question:  when
I'm adding an attachment and/or a text message file, I'd like to
have access to bash's autocompletion.  I _seriously_ do not want to
send out an email to 150 people with an empty message file, or that
tells recipients to look for an attachment file that isn't there.
So far it hasn't happened, but only because I make sure to pay very
close attention each time I send mail to one of my lists.

And, to be honest, I'm really lazy and don't want to bother checking
to see if I've typed the filenames correctly.

Any suggestions?

-- 
Lance Simmons



More information about the Discuss mailing list