Skip to main content

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:

code:
while [ -z $fname ];      echo "please insert @ least 1 character"
see more bash test operators:

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:

code:
if [ $fname == "quit" ];      echo "bye!"      exit  if
you made same mistake in second test (the 'while' loop).


Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk infinite loop


Ubuntu

Comments

Popular posts from this blog

Thread: Setting up a query server

After Effects error:creating resource file on Windows

Thread: Firefox print dialog doesn't remember settings