user1671375
user1671375

Reputation: 279

Echo text directly after variable

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

Answers (3)

paxdiablo
paxdiablo

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

echo_Me
echo_Me

Reputation: 37233

u can try this

  echo $min."m ".$sec."s ";

edit>

the output is 
 5m 15s

Upvotes: 1

William N
William N

Reputation: 430

echo $min."m ".$sec."s"; is one way of doing it

Upvotes: 3

Related Questions