I have the following string
my_str="A:Apple|B:Ball|C:Cat"
and I want to echo the following
A for Apple
B for Ball
C for Cat
The code I use is
IFS="|"
delimiter=':'
my_str="A:Apple|B:Ball|C:Cat"
for pair in ${my_str}; do
#echo "${pair}"
s=$pair$delimiter
var1=${s%%"$delimiter"*}
var2=${s#*"$delimiter"}
echo "${var1} for ${var2}"
done
But the output I get is
A for Apple:
B for Ball:
C for Cat:
Could someone help me remove the extra delimiter appended at the end?