[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: more bash questions




charles@lunarmedia.net wrote:
> 
> All-
> 
> I am tring to get a statement where I request input from the user, and
> when a carriage return is entered with no data the script moves to the
> next step. So far I have:
> 
> while read USER; do
>         if [ -n $USER ]; then
>                 echo $USER >> /tmp/allow.users
>         else
>                 echo "Thank you."
>         fi
> done
> 
> But its not ending when I enter a blank line. I think its because the
> minute the user enters the first bit a requested data, then $USER is not
> null, so the loop will never end.
> I am fairly certain what I want to do is pretty easy, but my first stab is
> not quite there. Can someone point out where to take this?
> 
> cjm

Well, $USER contains the carriage return, so it's not exactly null. 
Replacing the if with [ x"$USER" != "x" ] and adding a ;break to the
thank you line does what you want.

--
To unsubscribe, send email to majordomo@luci.org with
"unsubscribe luci-discuss" in the body.