How to end a variable name in a string without space

How can I end a variable name in a string without using a space or any other special character?

For example, is there anything I can put between $numand stfor output 1stinstead1 st

$num = 1;
echo "$num st";

Without using a point operator for concatenation

+5
source share
2 answers

Replace the variable name with curly braces.

$num = 1;
echo "${num}st";

Or use syntax printfinstead of simple interpolation:

$num = 1;
printf("%dst", $num);
+10
source

Use the concatenation character .:

echo $num . 'st';
0
source

All Articles