Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

nested while loop doesn't work

3 views
Skip to first unread message

kart...@gmail.com

unread,
Jun 4, 2013, 7:09:31 AM6/4/13
to bug-...@gnu.org, ba...@packages.debian.org
Configuration Information [Automatically generated, do not change]:
Machine: i686
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='i686' -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i686-pc-linux-gnu' -DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H -I. -I../bash -I../bash/include -I../bash/lib -D_FORTIFY_SOURCE=2 -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -Wall
uname output: Linux kartikkg 3.2.0-34-generic-pae #53-Ubuntu SMP Thu Nov 15 11:11:12 UTC 2012 i686 i686 i386 GNU/Linux
Machine Type: i686-pc-linux-gnu

Bash Version: 4.2
Patch Level: 24
Release Status: release

Description:
A while inside a while loop (nested while) doesnt work and also the vim /gvim doesnt highlight the second while loop
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

Repeat-By:
[Describe the sequence of events that causes the problem
to occur.]

Fix:
[Description of how to fix the problem. If you don't know a
fix for the problem, don't include this section.]

Greg Wooledge

unread,
Jun 4, 2013, 4:15:48 PM6/4/13
to kart...@gmail.com, bug-...@gnu.org, ba...@packages.debian.org
On Tue, Jun 04, 2013 at 04:39:31PM +0530, kart...@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.)

John Kearney

unread,
Jun 4, 2013, 5:27:36 PM6/4/13
to kart...@gmail.com, bug-...@gnu.org, ba...@packages.debian.org
as greg say this is the wrong list you need to report this to
" Vim syntax file
" Language: shell (sh) Korn shell (ksh) bash (sh)
" Maintainer: Dr. Charles E. Campbell, Jr.
<NdrO...@PcampbellAfamily.Mbiz>
" Previous Maintainer: Lennart Schultz <Lennart...@ecmwf.int>
" Last Change: Dec 09, 2011
" Version: 121
" URL:
[1]http://mysite.verizon.net/astronaut/vim/index.html#vimlinks_syntax

the file that does this is /usr/share/vim/vim73/syntax/sh.vim in an
ubuntu system.


and this is probably a simpler example to work with
#!/bin/bash
while true; do
while true; do
done
until true; do
done
done
until true; do
while true; do
done
until true; do
done
done
cheers



Gesendet: Dienstag, 04. Juni 2013 um 22:15 Uhr
Von: "Greg Wooledge" <woo...@eeg.ccf.org>
An: kart...@gmail.com
Cc: bug-...@gnu.org, ba...@packages.debian.org
Betreff: Re: nested while loop doesn't work
References

1. https://3c.web.de/mail/client/dereferrer?redirectUrl=http%3A%2F%2Fmysite.verizon.net%2Fastronaut%2Fvim%2Findex.html%23vimlinks_syntax&selection=tfol11a7bad28b16cbfe
0 new messages