From man bash
on readarray
:
-t
Remove any trailing newline from a line read, before it is assigned to an array element.
Is -t default behavior for readarray in bash?
I tested it couple of times with -t and without on a file with newlines no difference noticed.
There is indeed a difference:
# Newlines are retained as part each array element
$ readarray foo <<EOF
> foo
> bar
> baz
> EOF
$ printf '%s' "${foo[@]}"
foo
bar
baz
# Newlines are stripped
$ readarray -t foo <<EOF
foo
bar
baz
EOF
$ printf '%s' "${foo[@]}"
foobarbaz
The format to printf
does not include a newline, so the first example only prints each element on a separate line because each element itself ends with a newline. In the second example, all three elements are printed on the same line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With