Echo text immediately after the variable

I have two variables named $min

and $sec

.

If $min = 5

and $sec = 15

I want to print this "5m 15s"

,echo "$min m $sec s";

But this gives "5 m 15 s". How do I get rid of the space?

+3


source to share


3 answers


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

is one way to do it



+3


source


You can use curly braces for this, as you do for many shells:

$min = 7;
$sec = 2;
echo "${min}m ${sec}s";

      

Result:



7m 2s

      

The parentheses are used to denote the variable name from the following text in situations where the greedy nature of the variables can cause problems.

So while $minm

trying to provide you with the contents of a variable minm

, ${min}m

will provide you with the contents of a variable min

followed by a letter m

.

+13


source


u can try this

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

      

change>

the output is 
 5m 15s

      

+1


source







All Articles