[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: bug using for i in ...
From: |
Soenke Petersen |
Subject: |
Re: bug using for i in ... |
Date: |
Fri, 21 Sep 2001 10:28:30 +0200 |
aln00@udcast.com wrote:
>
> Configuration Information [Automatically generated, do not change]:
> Machine: i386
> OS: linux-gnu
> Compiler: gcc
> Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='i386'
> -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i386-pc-linux-gnu'
> -DCONF_VENDOR='pc' -DSHELL -DHAVE_CONFIG_H -D_FILE_OFFSET_BITS=64 -I.
> -I/usr/include -I/home/debian/src/bash/bash-2.05
> -I/home/debian/src/bash/bash-2.05/include
> -I/home/debian/src/bash/bash-2.05/lib -I/usr/include -g -O2
> uname output: Linux leda 2.2.19i #2 Mon Jun 11 22:55:44 CEST 2001 i686 unknown
> Machine Type: i386-pc-linux-gnu
>
> Bash Version: 2.05
> Patch Level: 0
> Release Status: release
>
> Description:
> Using:
> for i in list; do echo $i; done
> returns an error when the list is empty.
>
> Repeat-By:
>
> 0-leda$ for i in 1 2 ; do echo $i; done
> 1
> 2
>
> 0-leda$ for i in ; do echo $i; done
> bash: syntax error near unexpected token `;'
Sorry, it's not a bug, it's bad programming style.
You have to check wether the list is empty or not:
>list="a b"; [ "$list" = "" ] || for i in $list; do echo $i; done
a
b
>
> list=""; [ "$list" = "" ] || for i in $list; do echo $i; done
>