From: Johannes Sixt <j.sixt@viscovery.net>
To: Chris Ridd <chris.ridd@isode.com>
Cc: no To-header on input <"unlisted-recipients:;"@eudaptics.com>,
git@vger.kernel.org
Subject: Re: [PATCH] Improve sed portability
Date: Thu, 12 Jun 2008 09:46:38 +0200 [thread overview]
Message-ID: <4850D45E.8000802@viscovery.net> (raw)
In-Reply-To: <484FEF71.2030909@isode.com>
Chris Ridd schrieb:
> Johannes Sixt wrote:
>> Chris Ridd schrieb:
>>> @@ -73,7 +73,7 @@ resolve_relative_url ()
>>> module_name()
>>> {
>>> # Do we have "submodule.<something>.path = $1" defined in
>>> .gitmodules file?
>>> - re=$(printf '%s' "$1" | sed -e 's/[].[^$\\*]/\\&/g')
>>> + re=$(printf "%s\n" "$1" | sed -e 's/[].[^$\\*]/\\&/g')
>>
>> You change sq into dq. Is this not dangerous? Shouldn't backslash-en be
>> hidden from the shell so that printf can interpret it?
>
> It is necessary to use double quotes. This:
>
> printf '%s\n' foobar
>
> prints a literal \, a literal n, and no newline:
>
> foobar\n
>
> Not desirable :-(
On both Linux and AIX 4.3 I see:
$ printf 'x\ny'; echo z
x
yz
The printf turns the \n into LF.
I mentioned this in the first place because I don't know what various
shells do with \n when they see "%s\n". But one way or the other, the \n
will be turned into LF, either by the shell or by printf. So it's not a
big deal.
> Of course, using a plain old:
>
> echo "$1"
>
> should work well too. Why is printf being used here and not echo, anyway?
Because the "$1" could contain character sequences that some 'echo'
implementations mangle.
-- Hannes
next prev parent reply other threads:[~2008-06-12 7:47 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-11 13:09 [PATCH] Improve sed portability Chris Ridd
2008-06-11 14:04 ` Johannes Sixt
2008-06-11 15:29 ` Chris Ridd
2008-06-11 16:39 ` Jeff King
2008-06-12 7:46 ` Johannes Sixt [this message]
2008-06-12 8:29 ` Chris Ridd
2008-06-12 9:07 ` Jeff King
2008-07-13 20:00 ` Jakub Narebski
2008-06-12 8:33 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4850D45E.8000802@viscovery.net \
--to=j.sixt@viscovery.net \
--cc="unlisted-recipients:;"@eudaptics.com \
--cc=chris.ridd@isode.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.