[NTLUG:Discuss] Auto-completion within a bash script?
Eric Waguespack
ewaguespack at gmail.com
Thu Apr 16 12:23:37 CDT 2009
On Thu, Apr 16, 2009 at 11:17 AM, Lance Simmons <simmons.lance at gmail.com> wrote:
>
> 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
>
> _______________________________________________
> http://www.ntlug.org/mailman/listinfo/discuss
well If I was doing this, I would take a different approach, but I
will try to address just the auto completion question.
I am not aware of any way to allow auto completion in a bash script,
(at the read prompt).
but if you start the script like this:
./_very_rudimentary_script attachment.txt
and then add this line
change
read ATTACHMENT
to
ATTACHMENT="$1"
then you would have your auto completion, though it would be at script
initiation, not during execution.
./e
More information about the Discuss
mailing list