bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bash "while do echo" can't function correctly


From: Pierre Gaston
Subject: Re: bash "while do echo" can't function correctly
Date: Wed, 13 Apr 2016 14:45:50 +0300



On Wed, Apr 13, 2016 at 2:34 PM, John McKown <john.archie.mckown@gmail.com> wrote:
On Wed, Apr 13, 2016 at 1:10 AM, Geir Hauge <geir.hauge@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 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)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]