[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
When to use printf instead of echo?
From: |
Peng Yu |
Subject: |
When to use printf instead of echo? |
Date: |
Mon, 26 Jul 2010 16:27:30 -0500 |
Hi,
Although echo is sufficient most of the time, my understanding is that
printf may be better for certain situations (for example, formatting
the width of a number). The manual doesn't explicitly mention in what
situations it is better to use printf than to use echo. I think that
this might have been compared before, but I don't find it. Could you
please let me know when to use printf instead of echo?
In particular, I want to print a string that has single quote, double
quote and dollar character. I could use " to enclose such string and
add '\' to escape " and $ in the string. But I can't use ' in to
enclose the string. It is still inconvenient to have too many escape
characters. I'm wondering what is the best way to print such string.
echo "\$XX\"'" # this works.
echo '$XX"\'' #this doesn't work.
--
Regards,
Peng
- When to use printf instead of echo?,
Peng Yu <=