Bug 84000 - for-statement expansion with IFS changed broken
Summary: for-statement expansion with IFS changed broken
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: bash
Version: 8.0
Hardware: i386
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Tim Waugh
QA Contact: Ben Levenson
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2003-02-10 21:37 UTC by Robert K. Moniot
Modified: 2007-04-18 16:50 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2003-02-25 14:16:45 UTC
Embargoed:


Attachments (Terms of Use)

Description Robert K. Moniot 2003-02-10 21:37:57 UTC
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.2) Gecko/20021120
Netscape/7.01

Description of problem:
The expansion of the list of a for statement does not work the same with IFS
changed as it does with the default IFS.  If the list consists of a variable
containing a list of items separated by IFS, and this variable is followed by
IFS and then another item, the last item in the variable's list is concatenated
with the following item.  This does not happen when IFS is blank space.


Version-Release number of selected component (if applicable):


How reproducible:
Always

Steps to Reproduce:
1.Run the script provided below.
2.
3.
    

Actual Results:  foo
bar
baz
next
foo
bar
baz next


Expected Results:  foo
bar
baz
next
foo
bar
baz
next


Additional info:
Here's the script that shows it

#! /bin/sh
TO_DO_LIST="foo bar baz"
for item in $TO_DO_LIST next
do
  echo $item
done

IFS=:
TO_DO_LIST="foo:bar:baz"
for item in $TO_DO_LIST:next
do
  echo $item
done

Comment 1 Tim Waugh 2003-02-25 14:16:45 UTC
Upstream maintainer clarified the issue to me in private mail: only the result
of the variable expansion is eligible for field splitting here.  Use 'echo
"$item"' to see more clearly what's going on; you get this output:

bar
baz
next
foo
bar
baz:next

This is how POSIX specifies field splitting to operate.


Note You need to log in before you can comment on or make changes to this bug.