sstephenson / bats

Bash Automated Testing System
MIT License
7.13k stars 517 forks source link

\r is not trimmed from the end of $output #78

Closed econnell closed 10 years ago

econnell commented 10 years ago

While writing a test that relied out the output of redis-cli, I was having issues matching the $output variable. Finally, echoing $output through cat -vt showed me there was a \r (^M) stuck on the end of the line.

redis-cli outputs \r\n as line endings even on unix systems for some odd reason.

As a workaround, i piped it through perl -pe 's/\W*$//'

You can test this by running:

run echo -en "0\r\n" echo "output: $output" | cat -vt [ "$output" = "0" ] # fails

duggan commented 10 years ago

Arguably, bats is performing correctly here, and this is a bug that should be filed against redis-cli.

sstephenson commented 10 years ago

I'm not sure it's Bats' job to normalize line endings.

If you want to strip all carriage returns from the output string:

output="${output//$'\r'}"