views:

105

answers:

3

I am trying to print a variable between curly braces as

Product_number{product_version}

I tried

echo "$product_number{$product_version}";

But that does not work. I don't understand why :(

+9  A: 

try using double braces:

echo "$product_number{{$product_version}}";

You can also do:

echo "$product_number{".$product_version."}";

{ followed by $ is treated specially. It is mainly used when you want to append a string immediately at the end of a variable's value:

$v = 'hack';
echo "I {$v}ed it";
codaddict
+1 for good explanation
Brendan Bullen
+2  A: 
echo $product_number . "{" . $product_version . "}";
NAVEED
+1  A: 

Escape the "{":

echo "$product_number\{$product_version}";
pascal
Did you try it?
codaddict
Yes, I did. I guess the problem was to avoid the use of "{}" as grouping elements in the expression. "{$product_version}" seems to give the same result as "${product_version}", which is just the contents of $product_version .
pascal