Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.debian.user > #176429
| From | "foo fighter" <lopiuh@gmx.net> |
|---|---|
| Newsgroups | linux.debian.user |
| Subject | Bash different behaviour of read / strings in jessie versus stretch (regression?) |
| Date | 2017-01-07 22:00 +0100 |
| Message-ID | <sX6fL-5fd-9@gated-at.bofh.it> (permalink) |
| Organization | linux.* mail to news gateway |
Hi,
the same code behaves different in jessie and stretch. Does someone know why, and if this could be a regression?
In jessie "version 1" and "version 2" behave identical. In stretch, "version 2" behaves different (only one item in array)
The code difference between "version 1" and "version 2" lies in quotation marks around $_inputstring
Yours lopiuh
Code:
#!/usr/bin/env bash
set -o errexit # (set -e)
set -o nounset # (set -u)
set -o pipefail #
shopt -s nullglob # enable
#shopt -s failglob
#set -o noglob
clear
echo "===========================Version 1==========================="
echo "Bash Version: $BASH_VERSION"
echo -n "IFS:"; echo "$IFS" | cat -vte
echo
unset _array; declare -a _array
_inputstring="$(echo -e "item01\nitem02\nitem03")"
echo "inputstring:"
echo -n "$_inputstring" | xxd; echo
read -ra _array <<<$(echo $_inputstring) # <<< NO -"- around string
#read -ra _array <<<"$_inputstring" #<--- only one item, even in jessie
#read -ra _array <<<$_inputstring #<--- only one item, even in jessie
echo "itemcount of array: ${#_array[@]}"
for i in "${_array[@]}"; do
echo -n "element: "; echo -n "$i" | xxd; echo
done
#
echo "===========================Version 2==========================="
echo "Bash Version: $BASH_VERSION"
echo -n "IFS:"; echo "$IFS" | cat -vte
echo
unset _array; declare -a _array
_inputstring="$(echo -e "item01\nitem02\nitem03")"
echo "inputstring:"
echo -n "$_inputstring" | xxd; echo
read -ra _array <<<$(echo "$_inputstring") # <<< WITH -"- around string
#read -ra _array <<<"$_inputstring" #<--- only one item, even in jessie
#read -ra _array <<<$_inputstring #<--- only one item, even in jessie
echo "itemcount of array: ${#_array[@]}"
for i in "${_array[@]}"; do
echo -n "element: "; echo -n "$i" | xxd; echo
done
exit
Output of jessie:
===========================Version 1===========================
Bash Version: 4.3.30(1)-release
IFS: ^I$
$
inputstring:
0000000: 6974 656d 3031 0a69 7465 6d30 320a 6974 item01.item02.it
0000010: 656d 3033 em03
itemcount of array: 3
element: 0000000: 6974 656d 3031 item01
element: 0000000: 6974 656d 3032 item02
element: 0000000: 6974 656d 3033 item03
===========================Version 2===========================
Bash Version: 4.3.30(1)-release
IFS: ^I$
$
inputstring:
0000000: 6974 656d 3031 0a69 7465 6d30 320a 6974 item01.item02.it
0000010: 656d 3033 em03
itemcount of array: 3
element: 0000000: 6974 656d 3031 item01
element: 0000000: 6974 656d 3032 item02
element: 0000000: 6974 656d 3033 item03
Output of stretch:
===========================Version 1===========================
Bash Version: 4.4.5(1)-release
IFS: ^I$
$
inputstring:
00000000: 6974 656d 3031 0a69 7465 6d30 320a 6974 item01.item02.it
00000010: 656d 3033 em03
itemcount of array: 3
element: 00000000: 6974 656d 3031 item01
element: 00000000: 6974 656d 3032 item02
element: 00000000: 6974 656d 3033 item03
===========================Version 2===========================
Bash Version: 4.4.5(1)-release
IFS: ^I$
$
inputstring:
00000000: 6974 656d 3031 0a69 7465 6d30 320a 6974 item01.item02.it
00000010: 656d 3033 em03
itemcount of array: 1
element: 00000000: 6974 656d 3031 item01
Back to linux.debian.user | Previous | Next — Next in thread | Find similar | Unroll thread
Bash different behaviour of read / strings in jessie versus stretch (regression?) "foo fighter" <lopiuh@gmx.net> - 2017-01-07 22:00 +0100
Re: Bash different behaviour of read / strings in jessie versus stretch (regression?) Greg Wooledge <wooledg@eeg.ccf.org> - 2017-01-09 15:00 +0100
Aw: Re: Bash different behaviour of read / strings in jessie versus stretch (regression?) "foo fighter" <lopiuh@gmx.net> - 2017-01-10 01:20 +0100
Re: Re: Bash different behaviour of read / strings in jessie versus stretch (regression?) Greg Wooledge <wooledg@eeg.ccf.org> - 2017-01-10 14:40 +0100
csiph-web