bug-bash
[Top][All Lists]
Advanced

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

Re: nested while loop doesn't work


From: Greg Wooledge
Subject: Re: nested while loop doesn't work
Date: Tue, 4 Jun 2013 16:15:48 -0400
User-agent: Mutt/1.4.2.3i

On Tue, Jun 04, 2013 at 04:39:31PM +0530, kartikkgk@gmail.com wrote:
> Description:
> A while inside a while loop (nested while) doesnt work and also the vim /gvim 
> doesnt highlight the second while loop

For issues with the vim/gvim highlighting, you'd need to report the
problem in vim, not in bash.

> example code is given
> 
> while [ "ka" = $name ] 
> do 
>   echo "nothing\n"
>   while [ "ka" = $name ] //this while is not highlighted
>   do
>     echo "everything\n"
>   done
> done

You have a quoting mistake here.  "$name" should be quoted, or this will
fail if the variable contains multiple words separate by spaces.

imadev:~$ name="first last"
imadev:~$ [ "ka" = $name ]
bash-4.3: [: too many arguments

This code should work:

while [ "ka" = "$name" ]
do
  printf "nothing\n\n"
  while [ "ka" = "$name" ]
  do
    printf "everything\n\n"
  done
done

(It goes into an infinite loop when name=ka, but presumably that's what
you wanted.)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]