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)

1
  • That works fine for me with GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin10.0) Commented Mar 7, 2010 at 19:42

1 Answer 1

5

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

tts="{${x/$'\r'/}}"
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, that was it. I had my script file with CRLFs, therefore the extra \r :-/
BTW I converted to LF and the original script worked just fine.
Just a diagnostic tip: pipe a variable value (or any string) to | od -a to see a character-by-character representation of it with whitespace and control characters showing with symbolic names. For instance, a \r shows as cr, \n as nl, \t as ht.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.