Bash different behaviour of read / strings in jessie versus stretch (regression?)
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
Reply to: