This has me completely stumped.
Basically, when I write a string to a file, and then read it back, the string does not equal itself.
How can I test that the string I read from the file is equal to the expected value?
Example:
➜ foo="foo\tbar"
➜ echo $foo > foo.txt
➜ bar=`head -n 1 foo.txt`
➜ printf $foo | od -x
0000000 6261 6463 6509 6766
0000010
➜ printf $bar | od -x
0000000 6261 6463 6509 6766
0000010
➜ [ $bar != $foo ] && echo "they are not equal ????"
they are not equal ????
It seems to me that the two variables are clearly equal. Why is bash evaluating them as not equal?
If I run the above tests without the \t
in the string, the equality works fine, so I thought the tab character has something to do with this.
However, if I set $bar
directly to $foo
($bar=$foo
) with the tab included, then the equality passes, so it can't be directly a result of there being a tab in the string.
What is going on here? How can I ensure the first line of a file matches a string with tabs?
All tests are run with zsh.