bug-bash
[Top][All Lists]
Advanced

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

Re: How to supply a string with space in it as parameter to a function?


From: Eric Blake
Subject: Re: How to supply a string with space in it as parameter to a function?
Date: Wed, 23 Jun 2010 19:50:05 -0600
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.10) Gecko/20100621 Fedora/3.0.5-1.fc13 Lightning/1.0b2pre Mnenhy/0.8.2 Thunderbird/3.0.5

On 06/23/2010 07:01 PM, Andres P wrote:
> On Wed, Jun 23, 2010 at 8:23 PM, Peng Yu <pengyu.ut@gmail.com> wrote:
>> Why printf is better than echo? Is this because printf is more robust than 
>> echo?
> 
> Because if a string that is to be printed happens to be an echo flag, such
> as -n or -e, there's no straight forward way of escaping it such as
> with printf %s.

And because if a string to be printed contains a backslash, behavior
differs wildly between shells on whether echo prints the backslash
literally or treats it as an escape, whereas with printf the behavior is
consistent.

And because POSIX says so.

-- 
Eric Blake   eblake@redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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