Thread (9 messages) 9 messages, 4 authors, 2025-02-27

Re: [PATCH] mk: don't escape '#' for `grep`

From: Alejandro Colomar <alx@kernel.org>
Date: 2025-02-27 19:00:20

Hi Jakub,

On Thu, Feb 27, 2025 at 05:28:00PM +0100, Jakub Wilk wrote:
* Alejandro Colomar [off-list ref], 2025-02-27 16:20:
quoted
quoted
  Now this latter will resolve to "\#".  If you want to write makefiles
  portable to both versions, assign the number sign to a variable:
    H := \#
    foo := $(shell echo '$H')
Alternatively, you could take advantage of the fact that in some shell
contexts # and \# mean the same thing:

  foo := $(shell echo ''\#)
Hmmm, sounds reasonable, since a # not preceeded by a space is not a
comment.

	alx@debian:~$ echo ''\#
	#
	alx@debian:~$ echo ''#
	#

I'll take this workaround.  I'll put this on the commit:

	Reported-by: Sergei Trofimovich [off-list ref]
	Cc: Florian Weimer [off-list ref]
	Cc: Boris Pigin [off-list ref]
	Suggested-by: Jakub Wilk [off-list ref]
quoted
The thing is, on my system, grep(1) is just fine with that escaped hash:

	$ echo '#foo' | grep '\#foo'
	#foo
The warning comes from GNU grep (>= 3.8): "Regular expressions with stray
backslashes now cause warnings, as their unspecified behavior can lead to
unexpected results."

You're probably not seeing the warnings because Debian patched them out:
https://bugs.debian.org/1019724
Ahhh, that makes sense.  Thanks!


Have a lovely night!
Alex

-- 
<https://www.alejandro-colomar.es/>

Attachments

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help