From owner-freebsd-bugs@FreeBSD.ORG Wed Aug 10 13:00:29 2011 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 45814106566C for ; Wed, 10 Aug 2011 13:00:29 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 2189F8FC19 for ; Wed, 10 Aug 2011 13:00:29 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id p7AD0S2G029468 for ; Wed, 10 Aug 2011 13:00:28 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id p7AD0Sbg029466; Wed, 10 Aug 2011 13:00:28 GMT (envelope-from gnats) Resent-Date: Wed, 10 Aug 2011 13:00:28 GMT Resent-Message-Id: <201108101300.p7AD0Sbg029466@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Peter Maloney Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2D424106564A for ; Wed, 10 Aug 2011 12:58:31 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22]) by mx1.freebsd.org (Postfix) with ESMTP id 02D5B8FC16 for ; Wed, 10 Aug 2011 12:58:31 +0000 (UTC) Received: from red.freebsd.org (localhost [127.0.0.1]) by red.freebsd.org (8.14.4/8.14.4) with ESMTP id p7ACwUBw044247 for ; Wed, 10 Aug 2011 12:58:30 GMT (envelope-from nobody@red.freebsd.org) Received: (from nobody@localhost) by red.freebsd.org (8.14.4/8.14.4/Submit) id p7ACwUL9044246; Wed, 10 Aug 2011 12:58:30 GMT (envelope-from nobody) Message-Id: <201108101258.p7ACwUL9044246@red.freebsd.org> Date: Wed, 10 Aug 2011 12:58:30 GMT From: Peter Maloney To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: misc/159642: bash shell fails to convert string to array when IFS is a space X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Aug 2011 13:00:29 -0000 >Number: 159642 >Category: misc >Synopsis: bash shell fails to convert string to array when IFS is a space >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Wed Aug 10 13:00:28 UTC 2011 >Closed-Date: >Last-Modified: >Originator: Peter Maloney >Release: 8.2-RELEASE >Organization: Brockmann Consult >Environment: FreeBSD bcnastest3.bc.local 8.2-RELEASE FreeBSD 8.2-RELEASE #0: Thu Feb 17 02:41:51 UTC 2011 root@mason.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC amd64 >Description: The bash shell fails to convert a string to an array when IFS is a space. Works as expected with the latest Ubuntu, and some old installations I tried: bash: 4.2.8(1)-release, linux: Ubuntu 11.04 64 bit bash: 3.2.39(1)-release, linux: Ubuntu 8.04.4 LTS 64 bit bash: 3.00.15(1)-release, linux: Red Hat Enterprise Linux ES release 4 32 bit $ IFS=' ' $ x="1 2 3 4" $ y=($x) $ echo ${y[0]} 1 $ IFS=',' $ x="1,2,3,4" $ y=($x) $ echo ${y[0]} 1 First line sets the "internal field separator" to a space (which should have no effect since default includes space). Second line creates a string with spaces in it. Third line sets y to an array given the input string from x (and conversion here uses the IFS variable set on line 1) Fourth line prints the first element of the array. Fifth line is the output. However, on FreeBSD, it doesn't work as expected. bash was built from /usr/ports/shells/bash/ $ bash -version GNU bash, version 4.1.9(0)-release (amd64-portbld-freebsd8.2) Copyright (C) 2009 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software; you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. $ ps | grep $$ 1201 0 S 0:01.00 bash $ which bash /usr/local/bin/bash $ IFS=$' ' $ x="1 2 3 4" $ y=($x) $ echo ${y[0]} 1 2 3 4 workaround (replace line 3): $ eval y=($x) result with workaround: $ echo ${y[0]} 1 Works when IFS is "," for some reason. I didn't test other special characters. $ IFS=$',' $ x="1,2,3,4" $ echo ${y[0]} $ y=($x) $ echo ${y[0]} 1 $ echo ${y[1]} 2 >How-To-Repeat: Run script (default IFS): x="1 2 3 4" y=($x) echo ${y[0]} or IFS=$' ' x="1 2 3 4" y=($x) echo ${y[0]} >Fix: workaround: replace: $ y=$(x) with $ eval y=($x) However, this is likely not a good "fix" since then the array is created with the default IFS, so there are possible side effects. >Release-Note: >Audit-Trail: >Unformatted: