bug-bash
[Top][All Lists]
Advanced

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

Brace Expansion doesn't handle whitespace gracefully


From: Wesley Hirsch
Subject: Brace Expansion doesn't handle whitespace gracefully
Date: Tue, 30 Aug 2016 14:43:33 -0400

Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64'
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-pc-linux-gnu'
-DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash'
-DSHELL -DHAVE_CONFIG_H   -I.  -I../. -I.././include -I.././lib
-D_FORTIFY_SOURCE=2 -g -O2 -fstack-protector-strong -Wformat
-Werror=format-security -Wall
uname output: Linux achilles 4.6.0-0.bpo.1-amd64 #1 SMP Debian
4.6.1-1~bpo8+1 (2016-06-14) x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 4.3
Patch Level: 30
Release Status: release

Description:
        Bash doesn't seem to handle unquoted spaces in brace expansion
in a way that
        allows wordsplitting:

        address@hidden:~$ function show_args(){ declare -a
ARGS=("$@") ; declare -p ARGS ; }
        address@hidden:~$ show_args {-r 12,-r 14,-r 17}
        declare -a ARGS='([0]="{-r" [1]="12,-r" [2]="14,-r" [3]="17}")'
        address@hidden:~$ show_args -r\ {12,14,17}
        declare -a ARGS='([0]="-r 12" [1]="-r 14" [2]="-r 17")'

        The desired output would be:
        declare -a ARGS='([0]="-r" [1]="12" [2]="-r" [3]="14" [4]="-r"
[5]="17")'

        The manual describes that wordsplitting occurs after brace
expansion, and says
        that any string is eligible to be brace expanded (with the
exception of ${ due
        to variable expansion issues), which presumably includes whitespace.

        Note that:
        show_args {-r\ 12,-r\ 14,-r\ 17}
        produces the same result as the second test, and is _not_ the
desired result.

        My guess is that is caused by the fact that initial
wordsplitting separates
        the components before brace expansion can get to them, but this is
        unintuitive, and either the behavior should change or the documentation
        should call out that you can't do this.

Repeat-By:
        function show_args(){ declare -a ARGS=("$@") ; declare -p ARGS ;  }
        show_args {-r 12,-r 14,-r 17}
        show_args -r\ {12,14,17}



reply via email to

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