bug-bash
[Top][All Lists]
Advanced

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

Re: conditional aliases are broken


From: Chet Ramey
Subject: Re: conditional aliases are broken
Date: Fri, 19 Aug 2011 09:48:59 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:5.0) Gecko/20110624 Thunderbird/5.0

On 8/19/11 6:38 AM, Roman Rakus wrote:
> On 08/18/2011 07:57 PM, Eric Blake wrote:
>> On 08/18/2011 08:53 AM, Roman Rakus wrote:
>>> On 08/18/2011 04:38 PM, Sam Steingold wrote:
>>>> how do I write a function that would print the same as
>>>> $ \ls | cat
>>> f3(){ printf "%s\n" "$@"; }
>>
>> "\n" looks funny in shell; even though POSIX requires that "\n" does not
>> treat the \ as an escape but as a literal character, stylistically, I
>> prefer writing "\\n" or '\n' to make it clear that I intended a literal
>> backslash.
>>
> Interesting. I would expect that "\\n" in printf will print out `\n'. Good
> to know.

printf performs its own backslash interpretation of the format string, so
Eric's point is that any word expansions may reduce the number of
backslashes printf sees.  This depends on the character following the
backslash, since double quotes enable backslash interpretation for only a
few specific characters.  "\n" will remain unchanged, since the `n' is not
one of the characters for which backslash is special, but "\\n" will
be expanded to "\n".

"\\n" will be transformed to "\n" by the time printf sees it, and printf
will translate that to newline.  '\\n' will be displayed as you expect.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/



reply via email to

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