Date: Thu, 18 Sep 2014 21:11:09 +0000 From: bugzilla-noreply@freebsd.org To: freebsd-bugs@FreeBSD.org Subject: [Bug 193759] New: Wrong behaviour of IFS='|' set in /bin/sh Message-ID: <bug-193759-8@https.bugs.freebsd.org/bugzilla/>
next in thread | raw e-mail | index | archive | help
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@FreeBSD.org Reporter: michipili@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.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-193759-8>