I have a file with contents like this:
FOO=#{Foo}
# may contain blank lines or lines with comments
BAR=#{Bar}
Now, I want to do some stuff with those that requires me to consider FOO
and #{Foo}
as separate entities. So I tried the following, to ensure that I get the data I want:
#!/bin/bash
while read -r line; do
variable="${line%\=*}"
toReplace="${line#*\=}"
echo "$toReplace"
printf "%s -> \$%s\n" "$toReplace" "$variable"
done < <(grep '=' myfile)
This outputs, to my great surprise, the following:
#{Foo}
-> $FOO
#{Bar}
-> $BAR
As you see, the toReplace
part of the line is not printed, although it is apparently extracted correctly.
I also tried echo -n "$toReplace"
, which printed nothing.
Why is this? What can I do about it?