Reputation: 279
I have 2 variables named $min
and $sec
.
If $min = 5
and $sec = 15
I want to print this "5m 15s"
, echo "$min m $sec s";
But that gives "5 m 15 s". How do I get rid of the blank space?
Upvotes: 5
Views: 25655
Reputation: 881113
You can use braces to do this, same as many shells:
$min = 7;
$sec = 2;
echo "${min}m ${sec}s";
The output of that is:
7m 2s
The braces serve to delineate the variable name from the following text in situations where the "greedy" nature of variables would cause problems.
So, while $minm
tries to give you the contents of the minm
variable, ${min}m
will give you the contents of the min
variable followed by the literal m
.
Upvotes: 15
Reputation: 37233
u can try this
echo $min."m ".$sec."s ";
edit>
the output is
5m 15s
Upvotes: 1