I'm new to bash.
I'm trying to write a script that will read data from a text find and declare some variables. In the example below we read from a tab delimited file "ab.txt" that looks like this:
a->AA
b->BB
Where -> denotes a tab.
I'm reading this data with this code:
#!/bin/bash
while read line
do
tmp=(${line///})
fieldName=${tmp[0]}
case $fieldName in
"a")
a=${tmp[1]}
;;
"b")
b=${tmp[1]}
;;
esac
done < "ab.txt"
echo "a:"
echo $a
echo "b:"
echo $b
echo "concat a,b"
echo $a$b
echo "concat b,a"
echo $b$a
This gives me "a" and "b" nicely, but will not concatenate a and b! The output is this:
a:
AA
b:
BB
concat a,b
BB
concat b,a
AA
What am I doing wrong?