tags:

views:

47

answers:

1

I'm trying to do some variable expansion in bash but somehow the result is truncated/rotated. Here's a sample my code:

x="no-cabac,level=3,ref=3,bframes=0,subme=0,weightp=0"
tts="{$x}"
echo $tts

This prints: }no-cabac,level=3,ref=3,bframes=0,subme=0,weightp=0

I expected: {no-cabac,level=3,ref=3,bframes=0,subme=0,weightp=0}

If I change tts to tts=abc{$x}qwe the output is }qweno-cabac,level=3,ref=3,bframes=0,subme=0,weightp=0

I tried escaping the braces and removing the quotes, still doesn't work. I know there's something that has to be escaped but I can't figure out what.

bash --version output: GNU bash, version 3.2.48(21)-release (i686-pc-cygwin)

+5  A: 

You're getting your $x from somewhere else, and it has a \r at the end. Try:

tts="{${x/$'\r'/}}"
Ignacio Vazquez-Abrams
Thanks, that was it. I had my script file with CRLFs, therefore the extra \r :-/
Mauricio Scheffer
BTW I converted to LF and the original script worked just fine.
Mauricio Scheffer