Thread: infinite loop
so i'm trying make script asks name right?
have this:
#!/bin/bash
echo -n "please enter forum name: "
read fname
if [ $fname = "quit" ]; echo "bye! "
exit
fi
while [ $fname= ]; do
echo "please insert @ least 1 character"
done
if don't enter anything, goes endless loop. want script go part if don't put character there
echo -n "please enter forum name: "
read fname
help?
there's few things going on there. but, first 1 @ 'while' statement. think want test null string, uses '-z' test:
see more bash test operators:code:while [ -z $fname ]; echo "please insert @ least 1 character"
http://tldp.org/ldp/abs/html/comparison-ops.html
still not going fix problem however, if $fname indeed null, loop execute. you've given no place go. there's no way user correct mistake , enter value $fname, loop keeps cycling. need give loop way out
edit: oh, forgot comment on first conditional statement. you've made classic mistake there , used assignment operator when meant use test operator. so, need change statement be:
you made same mistake in second test (the 'while' loop).code:if [ $fname == "quit" ]; echo "bye!" exit if
Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk infinite loop
Ubuntu
Comments
Post a Comment