From: Junio C Hamano <gitster@pobox.com>
To: Johannes Sixt <j.sixt@viscovery.net>
Cc: Chris Ridd <chris.ridd@isode.com>, git@vger.kernel.org
Subject: Re: [PATCH] Improve sed portability
Date: Thu, 12 Jun 2008 01:33:14 -0700 [thread overview]
Message-ID: <7vy75b833p.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: 484FDB5D.7060606@viscovery.net
Johannes Sixt <j.sixt@viscovery.net> writes:
> Chris Ridd schrieb:
>> On Solaris /usr/bin/sed apparently fails to process input that doesn't
>> end in a \n. Consequently constructs like
>>
>> re=$(printf '%s' foo | sed -e 's/bar/BAR/g' $)
>>
>> cause re to be set to the empty string.
>
> So does /usr/bin/sed of AIX 4.3!
>
>> @@ -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?
"\n" inside dq is _not_ interpreted by the shell (printf interprets it),
but I tend to agree that using sq is worry-free and better.
>> name=$( git config -f .gitmodules --get-regexp '^submodule\..*\.path$' |
>> sed -n -e 's|^submodule\.\(.*\)\.path '"$re"'$|\1|p' )
>
> I trust you have tested this. But I wonder whether this leaves a stray
> newline in $re that gets in the way inside the sed expression...
I suspect the very original was written (or copied from something that
wrote) like this:
re=$(echo -n "$1" | sed -e '...')
and mechanically replaced to
re=$(printf '%s' "$1" | sed -e '...')
because "echo" is not quite portable.
But the original misunderstands the command substitution. The trailing LF
is removed by it, so as long as "$1" is a single line, $re will get a line
without the trailing LF _anyway_.
prev parent reply other threads:[~2008-06-12 8:34 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
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 [this message]
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=7vy75b833p.fsf@gitster.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=chris.ridd@isode.com \
--cc=git@vger.kernel.org \
--cc=j.sixt@viscovery.net \
/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.