Reputation: 153
I'm having issues with the following bash script trying to parse a version number from a WordPress readme file.
cat readme.txt | {
while read -r a b c d; do
if [ ${a} == "Stable" ] && [ ${b} == "tag:" ]; then
VERSION="$c"
fi
done
out="Updated to version $VERSION thanks"
echo $out
}
The output I expect is
Updated to version 1.15 thanks
but the actual output is
thanks to version 1.15
as though the 'thanks' is replacing the front of the string, not being appended to the end. Any clues?
Upvotes: 1
Views: 114
Reputation: 2337
If you pipe the output to cat -A
you will likely find out that $VERSION
contains a carriage return.
You can get rid of the CRs with tr
:
$ echo $'foo\rb'
boo
$ echo $'foo\rb' | tr -d '\r'
foob
Upvotes: 1
Reputation: 531155
readme.txt
and/or your script has DOS line endings; the value of VERSION
has a trailing carriage return which affects the output.
Upvotes: 4