[NTLUG:Discuss] Auto-completion within a bash script?
Lance Simmons
simmons.lance at gmail.com
Thu Apr 16 20:22:23 CDT 2009
On Thu, Apr 16, 2009 at 6:45 PM, Leroy Tennison <leroy_tennison at prodigy.net>
wrote:
>
> An option I use a fair amount in scripts is to print a help message if there
> are no command line arguments. That way I don't have to remember anything,
> just execute the script knowing it won't run but giving me the help I need.
I hit upon that solution earlier today, and I'm using it for the items for
which I want autocompletion. Thanks for confirming that this way works for
you. Now I don't have to fret that I've mis-typed a filename.
If anyone's interested, the relevant changes are:
> #!/bin/sh
>
> # Check for arguments
> if [ "$2" = "" ]; then
> echo 'USAGE: (1) file with addresses (2) file with message [3] [optional attachment]'; exit 0
> fi
>
> # Repeat the arguments
> echo Addresses: "$1"
> echo Message: "$2"
> if [ "$3" = "" ]; then
> echo No attachment
> else
> echo Attachment: "$3"
> fi
>
> # Get subject
> echo Subject:
> read SUBJECT
> echo Subject: "$SUBJECT"
>
> # Get final approval
> echo If OK, enter YES
> read ANSWER
>
> # If YES, then mail
> if [ "$ANSWER" = "YES" ]; then
>
> # mail without attachment
> [blah blah]
>
> # mail with attachment
> [blah blah]
>
> # If not YES, exit
> else
> echo You did not say YES.
> fi
>
> exit 0
--
Lance Simmons
More information about the Discuss
mailing list