How can I write variables to same line of a file?

I am trying to keep variables in a file.

if I have all variables at the same time, I can write them all like below.

echo $var1","$var2","$var3

But, these variables are being calculated at different times then they are lost
so I want to keep them in a file seperated by "," .

echo $var1 >> log_file
.
.
.
.
echo ","$var2 >> log_file
.
.
.

is there an option of echo in order to write the variables without creating a new line in the log file.

thanks in advance

Hello snr_silencer,

You can keep them in a single variable and then finally you can print them as follows.

VAR2=$VAR1","$VAR2
VAR3=$VAR2","$VAR3
echo $VAR3 > Input_file

Hope this helps, letme know if you have any queries.

Thanks,
R. Singh

echo -n "${var1}," >> log_file
.
.
echo -n "${var2}," >> log_file
.
.

or

printf "${var1}," >> log_file
.
.
printf "${var2}," >> log_file

thanks for your quick answers
-n worked

---------- Post updated at 10:50 AM ---------- Previous update was at 10:36 AM ----------

ps: -n option doesnt work in ksh, only works for bash shell

That's when you use the built-in echo . Check if there exists /bin/echo and see its man page.

The behavior of echo varies considerably from system to system, shell to shell, and with various environment variable settings when there are any backslash ( \ ) characters in any of the arguments and when the 1st character of the 1st argument is a minus sign ( - ) character. Using printf instead of echo in these conditions will prevent lots of headaches later if you ever move to a different environment or if some other user with a different shell or environment variables tries to use your code.