bug-bash
[Top][All Lists]
Advanced

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

Syntax error with background jobs in loops


From: Toby Kelsey
Subject: Syntax error with background jobs in loops
Date: Thu, 08 Jun 2006 11:34:14 +0100
User-agent: Mozilla Thunderbird 1.0.8 (X11/20060502)

Configuration Information [Automatically generated, do not change]:
Machine: i486
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='i486' -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i486-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   -g 
-O2
uname output: Linux hairy 2.6.12-10-686 #1 Fri Apr 28 13:21:56 UTC 2006 i686 GNU/Linux
Machine Type: i486-pc-linux-gnu

Bash Version: 3.0
Patch Level: 16
Release Status: release

Description:

The following bash loop works:

  for i in 30 31 32
  do sleep $i &
  done

but this gives a syntax error:

  for i in 31 31 32 ; do sleep $i & ; done

As a work-around you can do:

  for i in 31 31 32; do sleep $i & true ; done
or
  for i in 31 31 32; do sleep $i & done

(note the last one should give a syntax error since it violates the for-loop
syntax "for name [ in word ] ; do list ; done", but instead it works)
but this reveals another bug which is that the 'jobs' command shows the
unsubstituted commands and thus you cannot distinguish the jobs, vis:

[1]   Running                 sleep $i &
[2]-  Running                 sleep $i &
[3]+  Running                 sleep $i &

According to the bash man page a 'control operator' is one of the following
symbols:
              || & && ; ;; ( ) | <newline>

which play the same syntactic role in defining comands, so the sequence
   & ;
should be as valid as the sequence
   & <newline>


Toby




reply via email to

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