bug-bash
[Top][All Lists]
Advanced

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

Spaces trimmed from $* when assigned while IFS is unset [was: Unexpected


From: Martijn Dekker
Subject: Spaces trimmed from $* when assigned while IFS is unset [was: Unexpected word splitting on $* ...]
Date: Wed, 27 Sep 2017 05:50:16 +0200
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:52.0) Gecko/20100101 Thunderbird/52.3.0

Op 20-06-17 om 02:13 schreef Kevin Brodsky:
> When IFS is unset, unquoted $* undergoes word splitting as if IFS=' ',
> and not the expected IFS=$' \t\n'.

Possibly related are the following two issues:

1. When IFS is unset, assignments of unquoted ${var-$*}, ${var+$*}, etc.
to a variable removes leading and trailing spaces from $* (but not tabs
or newlines). (Modernish ID: BUG_PP_03B)
This issue exists on bash 4.3, 4.4 and current git.

Test script:

set "  abc  " " def  ghi " "jkl "
unset -v IFS var
var=${var-$*}/${var-$*}
printf '[%s]\n' "$var"

Actual output:
[abc def ghi jkl/abc def ghi jkl]

Expected output:
[  abc    def  ghi  jkl /  abc    def  ghi  jkl ]

2. When IFS is unset, conditional assignments of unquoted $* to a
variable within a parameter substitution, e.g. ${var=$*} or ${var:=$*},
removes leading and trailing spaces (but not tabs or newlines).
(Modernish ID: BUG_PP_04A)
This issue exists on all bash versions from current git down to at least
2.05b.

set "  abc  " " def  ghi " "jkl "
unset -v IFS var
: ${var:=$*/$*/${var-$*}}
printf '[%s]\n' "$var"

Actual output:
[abc def ghi jkl / abc def ghi jkl /abc def ghi jkl]

Expected output:
[  abc    def  ghi  jkl /  abc    def  ghi  jkl /  abc    def  ghi  jkl ]

Thanks,

- Martijn



reply via email to

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