[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#20553: 'echo -e' does not escape backslash correctly
From: |
Eric Blake |
Subject: |
bug#20553: 'echo -e' does not escape backslash correctly |
Date: |
Mon, 11 May 2015 17:36:50 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 |
On 05/11/2015 04:14 PM, Pádraig Brady wrote:
>> echo -e "net use z: \\\\srv\\aqs /persistent:no /user:%USERNAME%
>> $BG_PASSWD\r"
'echo -e' is non-portable. POSIX recommends that you use printf
instead, as the POSIX version of echo is supposed to behave as follows:
$ echo -e 'a\nb'
-e a\nb
You are relying on non-POSIX behavior for backslash interpolation.
> Note echo is not portable to other systems, and if that's required,
In fact, it's not even portable to bash:
$ shopt -s xpg_echo
tells bash to turn on POSIX rules for echo, invalidating any bash script
that relies on 'echo -e'.
> printf(1) is a better option, though that will have different
> quoting again due to the % chars etc.
% doesn't need quoting in shell. But yes, printf is more portable.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature