Why are the last two array elements being truncated?
I'm trying to generate an array from a string in bash, using a \n as the delaminating character. Using command substitution and tr I was close to what I wanted, now I'm getting strange output.
Script file below
input string: abcd\nefgh\nijkl\nmnop
#!/bin/bash
oper () {
local fct=$1
local s=$2
IFS='\n' read -ra sArr <<< "$s"
for item in ${sArr[@]}
do
printf " %s\n" $(echo $item | rev)
done
}
echo "original string: $2"
oper $1 $2
printf "mirror string: "
exit 0
Here's the output
original string: abcd\nefgh\nijkl\nmnop
dcba
hgfe
lkji
m
po