If you must initialize $input, then set it to "". Then test if $input has
a value after you get it from the user. If $input has a value then
continue with your wc, etc. If your assignment was to accept no more than
two words, then you'll need to save the wc -w output in another variable
and test if it equals two. If not, then tell the user to enter new data.
Also, there's no reason to cat the crap. ;-) Just give it as input to wc
like this:
wc -w crap
~M
Juland Re Perales, R said:
> Hey all, I'm a UNIX newb.
>
> I've been trying to get this script to work for a class and there's no
> competent being in this campus to help me out.
>
> Here it is:
>
>>A SCRIPT<
>
> ### Display a 2-line prompt for input until no input s received.
>
> input="a"
> nullvar=""
> echo "Word and Character Counter..."
>
>
> ###To prompt user to type words
>
> while [ $input -ne $nullvar ]
> do
> echo "Type one or two words, then press <Enter>"
> echo "To end, just press <Enter>"
> read input ###To exit program or display
> count output
> echo $input > crap ###Stores the read var into file
> 'crap'
> if [ "$input" = "$nullvar" ] ###if empty then you will exit
> then
> echo Exiting Program...
> else
> echo You typed `cat crap | wc -w` words and `cat crap | wc -c`
> characters
> echo ###to insert blank line
> fi
> done
>
>>A SCRIPT<
>
> Basically, I'm trying to get input from keyboard, and that input has to be
> either 1 or 2 words. If there is no input, the program exits. If there
> is
> input, then the program counts the # of chars and # of words.
>
> I would really appreciate the help... :)
>
>
> ---------------------------------------------------
> PLUG-discuss mailing list - PLUG-discuss@lists.plug.phoenix.az.us
> To subscribe, unsubscribe, or to change you mail settings:
> http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss
>