On Wed, Apr 13, 2016 at 6:45 AM, Pierre Gaston <pierre.gas...@gmail.com>
wrote:

>
>
> On Wed, Apr 13, 2016 at 2:34 PM, John McKown <john.archie.mck...@gmail.com
> > wrote:
>
>> On Wed, Apr 13, 2016 at 1:10 AM, Geir Hauge <geir.ha...@gmail.com> wrote:
>>
>> ​...
>>
>>
>>> though printf should be preferred over echo:
>>>
>>>     while read -r line; do printf '%s\n' "$line"; done < test.txt
>>>
>>
>> ​I've never read about using printf in preference to echo. Why is that?
>> ​I have used it myself in special cases, such as wanting leading zeros
>> (i=0;printf '%03d\n' "${i}";)
>>
>
>
> Posix says:
>
> It is not possible to use *echo* portably across all POSIX systems unless
> both *-n* (as the first argument) and escape sequences are omitted.
> The *printf*
> <http://pubs.opengroup.org/onlinepubs/9699919799/utilities/printf.html>
> utility can be used portably to emulate any of the traditional behaviors of
> the *echo* utility as follows (assuming that *IFS* has its standard value
> or is unset)
>

​Ah. Thanks. I only use BASH and the GNU infrastructure, so I have never
run into that problem. I think I'll change my habits, just in case I run
across a system which doesn't have it (especially in my scripts)


-- 
How many surrealists does it take to screw in a lightbulb? One to hold the
griffon and one to fill the bathtub with brightly colored LEDs.

Maranatha! <><
John McKown

Reply via email to