[Bug 193759] New: Wrong behaviour of IFS='|' set in /bin/sh
bugzilla-noreply at freebsd.org
bugzilla-noreply at freebsd.org
Thu Sep 18 21:11:09 UTC 2014
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=193759
Bug ID: 193759
Summary: Wrong behaviour of IFS='|' set in /bin/sh
Product: Base System
Version: 10.0-RELEASE
Hardware: Any
OS: Any
Status: Needs Triage
Severity: Affects Only Me
Priority: ---
Component: bin
Assignee: freebsd-bugs at FreeBSD.org
Reporter: michipili at gmail.com
Using IFS to set positional parameters as in
IFS='|' set -- $line
displays erratic behaviour. In the script below, the expected output is
A-1-2
B-1-2
C-1-2
but the first splitting is handled specially and we get
A|1|2--
B-1-2
C-1-2
----8<----
mock()
{
cat <<EOF
A|1|2
B|1|2
C|1|2
EOF
}
demonstrate()
{
while read line; do
IFS='|' set -- $line
printf '%s-%s-%s\n' "$1" "$2" "$3"
done
}
mock | demonstrate
---->8----
Note that splitting twice fixes the output.
----8<----
demonstrate2()
{
while read line; do
# The following line has been intentionally duplicated
IFS='|' set -- $line
IFS='|' set -- $line
printf '%s-%s-%s\n' "$1" "$2" "$3"
done
}
mock | demonstrate2
---->8----
--
You are receiving this mail because:
You are the assignee for the bug.
More information about the freebsd-bugs
mailing list